From patchwork Fri Jul 21 07:55:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1810762 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=H8PWD5Xd; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R6hhC2P06z1yYc for ; Fri, 21 Jul 2023 17:56:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 334613865C1D for ; Fri, 21 Jul 2023 07:56:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 334613865C1D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689926169; bh=ai08TIGPi91Ue3WXe8wOZoMniODqJ/r/uFaUq1uxvrg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=H8PWD5Xdn/2e+EZeQr4c2sDnvtDvNKAx/9rkQB9EvRfadR7ujavWl36nSSq9PjT3M 1oOO3CgRsHl5kc/hjR+iyIKFWRnEHMZEHYNpqAX79STpb/hkdRlKc2jHHHSqG0O6Ko XPmpEBuLRzTbTgQ0rJW82pfSnnaKW5ZMhzpPPtBo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id B8DA2385043F for ; Fri, 21 Jul 2023 07:55:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B8DA2385043F Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 716FF28261A; Fri, 21 Jul 2023 09:55:39 +0200 (CEST) Date: Fri, 21 Jul 2023 09:55:39 +0200 To: gcc-patches@gcc.gnu.org Subject: Improve loop dumping Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, we have flow_loop_dump and print_loop. While print_loop was extended to dump stuff from loop structure we added over years (loop info), flow_loop_dump was not. -fdump-tree-all files contains flow_loop_dump which makes it hard to see what metadata we have attached to loop. This patch unifies dumping of these fields from both functions. For example for: int a[100]; main() { for (int i = 0; i < 10; i++) a[i]=i; } we now print: ;; Loop 0 ;; header 0, latch 1 ;; depth 0, outer -1 ;; nodes: 0 1 2 3 4 5 ;; ;; Loop 1 ;; header 4, latch 3 ;; depth 1, outer 0, finite_p ;; upper_bound 10 ;; likely_upper_bound 10 ;; estimate 10 ;; iterations by profile: 10.001101 (unreliable) finite_p, upper_bound, likely_upper_bound estimate and iterations by profile is new. Bootstrap/regtest on x86_64 in progress. OK if it passes? Honza gcc/ChangeLog: * cfgloop.cc (flow_loop_dump): Use print_loop_info. * cfgloop.h (print_loop_info): Declare. * tree-cfg.cc (print_loop_info): Break out from ...; add printing of missing fields and profile (print_loop): ... here. diff --git a/gcc/cfgloop.cc b/gcc/cfgloop.cc index 020e5734d95..9ca85e648a7 100644 --- a/gcc/cfgloop.cc +++ b/gcc/cfgloop.cc @@ -135,17 +135,12 @@ flow_loop_dump (const class loop *loop, FILE *file, fprintf (file, "\n"); } - fprintf (file, ";; depth %d, outer %ld\n", + fprintf (file, ";; depth %d, outer %ld", loop_depth (loop), (long) (loop_outer (loop) ? loop_outer (loop)->num : -1)); + print_loop_info (file, loop, ";; "); - bool reliable; - sreal iterations; - if (loop->num && expected_loop_iterations_by_profile (loop, &iterations, &reliable)) - fprintf (file, ";; profile-based iteration count: %f %s\n", - iterations.to_double (), reliable ? "(reliable)" : "(unreliable)"); - - fprintf (file, ";; nodes:"); + fprintf (file, "\n;; nodes:"); bbs = get_loop_body (loop); for (i = 0; i < loop->num_nodes; i++) fprintf (file, " %d", bbs[i]->index); diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h index 4d2fd4b6af5..269694c7962 100644 --- a/gcc/cfgloop.h +++ b/gcc/cfgloop.h @@ -411,6 +411,7 @@ extern unsigned expected_loop_iterations (class loop *); extern rtx doloop_condition_get (rtx_insn *); void mark_loop_for_removal (loop_p); +void print_loop_info (FILE *file, const class loop *loop, const char *); /* Induction variable analysis. */ diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 7ccc2a5a5a7..a6c97a04662 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -8479,6 +8479,55 @@ print_loops_bb (FILE *file, basic_block bb, int indent, int verbosity) } } +/* Print loop information. */ + +void +print_loop_info (FILE *file, const class loop *loop, const char *prefix) +{ + if (loop->can_be_parallel) + fprintf (file, ", can_be_parallel"); + if (loop->warned_aggressive_loop_optimizations) + fprintf (file, ", warned_aggressive_loop_optimizations"); + if (loop->dont_vectorize) + fprintf (file, ", dont_vectorize"); + if (loop->force_vectorize) + fprintf (file, ", force_vectorize"); + if (loop->in_oacc_kernels_region) + fprintf (file, ", in_oacc_kernels_region"); + if (loop->finite_p) + fprintf (file, ", finite_p"); + if (loop->unroll) + fprintf (file, "\n%sunroll %d", prefix, loop->unroll); + if (loop->nb_iterations) + { + fprintf (file, "\n%sniter ", prefix); + print_generic_expr (file, loop->nb_iterations); + } + + if (loop->any_upper_bound) + { + fprintf (file, "\n%supper_bound ", prefix); + print_decu (loop->nb_iterations_upper_bound, file); + } + if (loop->any_likely_upper_bound) + { + fprintf (file, "\n%slikely_upper_bound ", prefix); + print_decu (loop->nb_iterations_likely_upper_bound, file); + } + + if (loop->any_estimate) + { + fprintf (file, "\n%sestimate ", prefix); + print_decu (loop->nb_iterations_estimate, file); + } + bool reliable; + sreal iterations; + if (loop->num && expected_loop_iterations_by_profile (loop, &iterations, &reliable)) + fprintf (file, "\n%siterations by profile: %f %s", prefix, + iterations.to_double (), reliable ? "(reliable)" : "(unreliable)"); + +} + static void print_loop_and_siblings (FILE *, class loop *, int, int); /* Pretty print LOOP on FILE, indented INDENT spaces. Following @@ -8511,27 +8560,7 @@ print_loop (FILE *file, class loop *loop, int indent, int verbosity) fprintf (file, ", latch = %d", loop->latch->index); else fprintf (file, ", multiple latches"); - fprintf (file, ", niter = "); - print_generic_expr (file, loop->nb_iterations); - - if (loop->any_upper_bound) - { - fprintf (file, ", upper_bound = "); - print_decu (loop->nb_iterations_upper_bound, file); - } - if (loop->any_likely_upper_bound) - { - fprintf (file, ", likely_upper_bound = "); - print_decu (loop->nb_iterations_likely_upper_bound, file); - } - - if (loop->any_estimate) - { - fprintf (file, ", estimate = "); - print_decu (loop->nb_iterations_estimate, file); - } - if (loop->unroll) - fprintf (file, ", unroll = %d", loop->unroll); + print_loop_info (file, loop, s_indent); fprintf (file, ")\n"); /* Print loop's body. */