From patchwork Sat Nov 16 01:23:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1196031 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513755-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="ov/P6S7C"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="hSRftOD6"; 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 47FHdK2RHSz9sPf for ; Sat, 16 Nov 2019 12:27:16 +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:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=CFC G903a5HFYbNCoBIjbe2w2CxAVXhi37U4cpInmBP/qxdoJRSSctHjVYQ02LCtfiIe /0f0sEe4kjdovEptRtPzlKjVx+ys01YOxBYybFPtwGsNQbxZRzgJRYJIUuJX/k1P pNRs2n7yieWZJSTUSjYv9SdhmrrExhxWtr5I09dk= 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:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=U+DlikR45 nFRApnzMNPf5ncr154=; b=ov/P6S7C/IdidtjOHgaPhkHK25rycgDvoUZ60I/N1 d1bTD4IH2y9ciIvLY5unBFUutVp0DgDBtGVk55YswnUZ3rvMynMwtOWNeFKWnCGk HKKFpQtKdO5G80zph72DtkdWy2RIXOO3A+rWpYGzup/dWqqWm+9wid2114RUtmZu XI= Received: (qmail 78045 invoked by alias); 16 Nov 2019 01:20:48 -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 61987 invoked by uid 89); 16 Nov 2019 01:18:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 16 Nov 2019 01:17:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573867075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J3Yg7GA3kXMCUx+uQ8MogbfDqdWSYHAtPf6N8mCiD+8=; b=hSRftOD6VNZu1ULP007Og3KHEw1W+R49yHtZViP5sjip2/w3JLoEzLREqmeBnshGjpvD7k 0/yIWBNYpesYSrG8hSnjgzG1jCZLbxYDhaGRdBy/FKTKaRShjSm0FgnzqXsfHU7WwJfy3p S4iwXYprL+q6QXjx76x3vws2dbWuyKI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-394-Jjot-r0PNcuOoaajlUCw5w-1; Fri, 15 Nov 2019 20:17:54 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9895107ACC4 for ; Sat, 16 Nov 2019 01:17:53 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-32.phx2.redhat.com [10.3.112.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFB2110246FB; Sat, 16 Nov 2019 01:17:52 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 39/49] analyzer: new files: analysis-plan.{cc|h} Date: Fri, 15 Nov 2019 20:23:26 -0500 Message-Id: <1573867416-55618-40-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1573867416-55618-1-git-send-email-dmalcolm@redhat.com> References: <1573867416-55618-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes This patch adds an analysis_plan class, which encapsulate decisions about how the analysis should happen (e.g. the order in which functions should be traversed). gcc/ChangeLog: * analyzer/analysis-plan.cc: New file. * analyzer/analysis-plan.h: New file. --- gcc/analyzer/analysis-plan.cc | 115 ++++++++++++++++++++++++++++++++++++++++++ gcc/analyzer/analysis-plan.h | 56 ++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 gcc/analyzer/analysis-plan.cc create mode 100644 gcc/analyzer/analysis-plan.h diff --git a/gcc/analyzer/analysis-plan.cc b/gcc/analyzer/analysis-plan.cc new file mode 100644 index 0000000..920783b --- /dev/null +++ b/gcc/analyzer/analysis-plan.cc @@ -0,0 +1,115 @@ +/* A class to encapsulate decisions about how the analysis should happen. + Copyright (C) 2019 Free Software Foundation, Inc. + Contributed by David Malcolm . + +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 "gcc-plugin.h" +#include "system.h" +#include "coretypes.h" +#include "tree.h" +#include "cgraph.h" +#include "timevar.h" +#include "ipa-utils.h" +#include "params.h" +#include "analyzer/analyzer.h" +#include "analyzer/analysis-plan.h" +#include "analyzer/supergraph.h" + +/* class analysis_plan. */ + +/* analysis_plan's ctor. */ + +analysis_plan::analysis_plan (const supergraph &sg, logger *logger) +: log_user (logger), m_sg (sg), + m_cgraph_node_postorder (XCNEWVEC (struct cgraph_node *, + symtab->cgraph_count)), + m_index_by_uid (symtab->cgraph_max_uid) +{ + LOG_SCOPE (logger); + auto_client_timevar tv ("creating analysis plan"); + + m_num_cgraph_nodes = ipa_reverse_postorder (m_cgraph_node_postorder); + gcc_assert (m_num_cgraph_nodes == symtab->cgraph_count); + if (get_logger_file ()) + ipa_print_order (get_logger_file (), + "analysis_plan", m_cgraph_node_postorder, + m_num_cgraph_nodes); + + /* Populate m_index_by_uid. */ + for (int i = 0; i < symtab->cgraph_max_uid; i++) + m_index_by_uid.quick_push (-1); + for (int i = 0; i < m_num_cgraph_nodes; i++) + { + gcc_assert (m_cgraph_node_postorder[i]->get_uid () + < symtab->cgraph_max_uid); + m_index_by_uid[m_cgraph_node_postorder[i]->get_uid ()] = i; + } +} + +/* analysis_plan's dtor. */ + +analysis_plan::~analysis_plan () +{ + free (m_cgraph_node_postorder); +} + +/* Comparator for use by the exploded_graph's worklist, to order FUN_A + and FUN_B so that functions that are to be summarized are visited + before the summary is needed (based on a sort of the callgraph). */ + +int +analysis_plan::cmp_function (function *fun_a, function *fun_b) const +{ + cgraph_node *node_a = cgraph_node::get (fun_a->decl); + cgraph_node *node_b = cgraph_node::get (fun_b->decl); + + int idx_a = m_index_by_uid[node_a->get_uid ()]; + int idx_b = m_index_by_uid[node_b->get_uid ()]; + + return idx_b - idx_a; +} + +/* Return true if the call EDGE should be analyzed using a call summary. + Return false if it should be analyzed using a full call and return. */ + +bool +analysis_plan::use_summary_p (const cgraph_edge *edge) const +{ + /* Don't use call summaries if -fno-analyzer-call-summaries. */ + if (!flag_analyzer_call_summaries) + return false; + + /* TODO: don't count callsites each time. */ + int num_call_sites = 0; + const cgraph_node *callee = edge->callee; + for (cgraph_edge *edge = callee->callers; edge; edge = edge->next_caller) + ++num_call_sites; + + /* Don't use a call summary if there's only one call site. */ + if (num_call_sites <= 1) + return false; + + /* Require the callee to be sufficiently complex to be worth + summarizing. */ + if ((int)m_sg.get_num_snodes (callee->get_fun ()) + < PARAM_VALUE (PARAM_ANALYZER_MIN_SNODES_FOR_CALL_SUMMARY)) + return false; + + return true; +} diff --git a/gcc/analyzer/analysis-plan.h b/gcc/analyzer/analysis-plan.h new file mode 100644 index 0000000..c9396ec --- /dev/null +++ b/gcc/analyzer/analysis-plan.h @@ -0,0 +1,56 @@ +/* A class to encapsulate decisions about how the analysis should happen. + Copyright (C) 2019 Free Software Foundation, Inc. + Contributed by David Malcolm . + +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_ANALYZER_ANALYSIS_PLAN_H +#define GCC_ANALYZER_ANALYSIS_PLAN_H + +#include "analyzer/analyzer-logging.h" + +/* A class to encapsulate decisions about how the analysis should happen. + Examples: + - the order in which functions should be analyzed, so that function + summaries are created before analysis of call sites that might use + them + - which callgraph edges should use call summaries + TODO: the above is a work-in-progress. */ + +class analysis_plan : public log_user +{ +public: + analysis_plan (const supergraph &sg, logger *logger); + ~analysis_plan (); + + int cmp_function (function *fun_a, function *fun_b) const; + + bool use_summary_p (const cgraph_edge *edge) const; + +private: + const supergraph &m_sg; + + /* Result of ipa_reverse_postorder. */ + cgraph_node **m_cgraph_node_postorder; + int m_num_cgraph_nodes; + + /* Index of each node within the postorder ordering, + accessed via the "m_uid" field. */ + auto_vec m_index_by_uid; +}; + +#endif /* GCC_ANALYZER_ANALYSIS_PLAN_H */