From patchwork Fri Dec 13 18:11:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1209348 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-515934-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="FWFVACTW"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="SpvBT9T4"; 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 47ZJkx0HXTz9sPV for ; Sat, 14 Dec 2019 05:16:08 +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 :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=rZlq8iGXnRCFQ2QSx4GrwALRq6YFKF25vQ4GiE3Ekc9nNp0v0vYce A0BnZf4bGa8z3XZ390/753+FzdPeLiP+31OFHtWLHek2VpoeaIsIIIF4j+gbrJYB +5SIQgTM+gFthipdigibBwFi1aviRKDQPgKYHZVCd3EPWX6IUKORTk= 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 :mime-version:content-type:content-transfer-encoding; s=default; bh=eQwYsDTgCDR4TMo+Wlz6lSETQrQ=; b=FWFVACTWhTWuiXztMQk0LhYvThWs 61bZ+GRFCMCOlgdyW4pv3LAVv44/3uPDC1eOjiOtsEYo6LlpMg+H2Y7Sie9Nnv/J 4JIFuUUtIOG1/kBa3aU7yVGMJQzGb0EHyMPZMG5JqFSCnua8VeVu6z1hi+JTHKCu 8trnobTqm2X9PGk= Received: (qmail 103026 invoked by alias); 13 Dec 2019 18:12:18 -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 101560 invoked by uid 89); 13 Dec 2019 18:12:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 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=reworking, sk:propert, vfunc X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.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; Fri, 13 Dec 2019 18:11:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576260713; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/IBxR7+9vk9vS2mn0ybloQO7dU3Up1oHKhcU6jcjxkg=; b=SpvBT9T4j4HBep7djT9IBcRU7RR5/4sFeMSou8r+c3bOLaMkJ48Z3ZGMd7mmLGHEdjYGVs x+kkWzoTWt4Yf6J77LDPDiHxi20YN0/umn61ku2uD+zOS9CIyLtEEeNNVGpHrxzGa2epVC YBh3O2Z1D3mXiO4SlryeJXxHmarsvOU= 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-102-J7Z3BfdzPcmPypa918JISg-1; Fri, 13 Dec 2019 13:11:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2E501005510 for ; Fri, 13 Dec 2019 18:11:48 +0000 (UTC) Received: from t470.redhat.com (ovpn-117-164.phx2.redhat.com [10.3.117.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F5205C219; Fri, 13 Dec 2019 18:11:48 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 19/45] analyzer: new file: analyzer-pass.cc and pass registration Date: Fri, 13 Dec 2019 13:11:08 -0500 Message-Id: <20191213181134.1830-20-dmalcolm@redhat.com> In-Reply-To: <20191213181134.1830-1-dmalcolm@redhat.com> References: <20191213181134.1830-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes Changed in v4: - Remove include of gcc-plugin.h, reworking includes accordingly. - Use TV_ANALYZER rather than TV_NONE for the pass - Add a gate function to the pass - Move the check for #if ENABLE_ANALYZER from the driver to the pass's execute vfunc - Expose the pass via make_pass_analyzer, rather than via the plugin pass registration mechanism Changed in v3: - added to passes.def and tree-pass.h gcc/ChangeLog: * analyzer/analyzer-pass.cc: New file. * passes.def (pass_analyzer): Add before pass_ipa_whole_program_visibility. * tree-pass.h (make_pass_analyzer): New decl. --- gcc/analyzer/analyzer-pass.cc | 102 ++++++++++++++++++++++++++++++++++ gcc/passes.def | 1 + gcc/tree-pass.h | 1 + 3 files changed, 104 insertions(+) create mode 100644 gcc/analyzer/analyzer-pass.cc diff --git a/gcc/analyzer/analyzer-pass.cc b/gcc/analyzer/analyzer-pass.cc new file mode 100644 index 000000000000..60535a944dc9 --- /dev/null +++ b/gcc/analyzer/analyzer-pass.cc @@ -0,0 +1,102 @@ +/* Integration of the analyzer with GCC's pass manager. + 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 "system.h" +#include "coretypes.h" +#include "context.h" +#include "tree-pass.h" +#include "diagnostic.h" +#include "options.h" +#include "analyzer/engine.h" + +namespace { + +/* Data for the analyzer pass. */ + +const pass_data pass_data_analyzer = +{ + IPA_PASS, /* type */ + "analyzer", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_ANALYZER, /* tv_id */ + PROP_ssa, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +/* The analyzer pass. */ + +class pass_analyzer : public ipa_opt_pass_d +{ +public: + pass_analyzer(gcc::context *ctxt) + : ipa_opt_pass_d (pass_data_analyzer, ctxt, + NULL, /* generate_summary */ + NULL, /* write_summary */ + NULL, /* read_summary */ + NULL, /* write_optimization_summary */ + NULL, /* read_optimization_summary */ + NULL, /* stmt_fixup */ + 0, /* function_transform_todo_flags_start */ + NULL, /* function_transform */ + NULL) /* variable_transform */ + {} + + /* opt_pass methods: */ + bool gate (function *) FINAL OVERRIDE; + unsigned int execute (function *) FINAL OVERRIDE; +}; // class pass_analyzer + +/* Only run the analyzer if -fanalyzer. */ + +bool +pass_analyzer::gate (function *) +{ + return flag_analyzer != 0; +} + +/* Entrypoint for the analyzer pass. */ + +unsigned int +pass_analyzer::execute (function *) +{ +#if ENABLE_ANALYZER + run_checkers (); +#else + sorry ("%qs was not enabled in this build of GCC" + " (missing configure-time option %qs)", + "-fanalyzer", "--enable-analyzer"); +#endif + + return 0; +} + +} // anon namespace + +/* Make an instance of the analyzer pass. */ + +ipa_opt_pass_d * +make_pass_analyzer (gcc::context *ctxt) +{ + return new pass_analyzer (ctxt); +} diff --git a/gcc/passes.def b/gcc/passes.def index 798a391bd351..0ee8b621016c 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -142,6 +142,7 @@ along with GCC; see the file COPYING3. If not see TERMINATE_PASS_LIST (all_small_ipa_passes) INSERT_PASSES_AFTER (all_regular_ipa_passes) + NEXT_PASS (pass_analyzer); NEXT_PASS (pass_ipa_whole_program_visibility); NEXT_PASS (pass_ipa_profile); NEXT_PASS (pass_ipa_icf); diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index a987661530ea..59a5fa6ad4a5 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -490,6 +490,7 @@ extern simple_ipa_opt_pass *make_pass_build_ssa_passes (gcc::context *ctxt); extern simple_ipa_opt_pass *make_pass_local_optimization_passes (gcc::context *ctxt); extern simple_ipa_opt_pass *make_pass_ipa_remove_symbols (gcc::context *ctxt); +extern ipa_opt_pass_d *make_pass_analyzer (gcc::context *ctxt); extern ipa_opt_pass_d *make_pass_ipa_whole_program_visibility (gcc::context *ctxt); extern simple_ipa_opt_pass *make_pass_ipa_increase_alignment (gcc::context