From patchwork Thu Mar 26 17:01:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 455138 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 95BF9140146 for ; Fri, 27 Mar 2015 04:01:36 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=vw+7uSBr; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=Pjp9ydQuTT2dBiYVJ ALo0daTmBzYxsuj6iqrjFadfeghM3nZLPHdrEhbYQq1ZW/4cm1aHSs7GCnDuKTT6 PIfycK5tuM2CFD9lqMPwilvKAYSKJYnxSGNXnCP1kCVcGB+1VSgG3lxi10psabY0 WTRYHv+8YqSikVdibMmePdIZP4= 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:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=TPVkLMfa3RvcT3Y6nH8gzhx wr/8=; b=vw+7uSBrrSiOXMx+e4QfQeQp+5ZSqAFP+a/qbIBu0pTGSYcnVPursyP PNU2UyXz+az9Ej5Peohf5+jNUCrSI451qzwFNYtCT4hdEzhLRyMtKZjcS7J+bZ2F XzAeFOErR1rNASA7MGRKmlR6XxLv8fCO5YFUM5mQARyv3mOl4kjo= Received: (qmail 125678 invoked by alias); 26 Mar 2015 17:01:28 -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 125660 invoked by uid 89); 26 Mar 2015 17:01:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 26 Mar 2015 17:01:25 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 6A7125469E6; Thu, 26 Mar 2015 18:01:21 +0100 (CET) Date: Thu, 26 Mar 2015 18:01:21 +0100 From: Jan Hubicka To: Jan Hubicka Cc: Richard Biener , gcc-patches@gcc.gnu.org Subject: Re: Discover nothorow functions before into_ssa Message-ID: <20150326170120.GD29341@kam.mff.cuni.cz> References: <20150326063251.GA29341@kam.mff.cuni.cz> <20150326144111.GG8802@atrey.karlin.mff.cuni.cz> <6A34C5F7-C1EA-45C6-ADF9-F649679C0673@suse.de> <20150326164854.GH8802@atrey.karlin.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150326164854.GH8802@atrey.karlin.mff.cuni.cz> User-Agent: Mutt/1.5.21 (2010-09-15) Hi, this is updated patch I am testing (along with the fixes to verifiew and inliner I will commit independently). * passes.def: Add pass_nothrow. * ipa-pure-const.c: (pass_data_nothrow): New. (pass_nothrow): New. (pass_nothrow::execute): New. (make_pass_nothrow): New. * tree-pass.h (make_pass_nothrow): Declare. Index: passes.def =================================================================== --- passes.def (revision 221682) +++ passes.def (working copy) @@ -58,6 +58,7 @@ along with GCC; see the file COPYING3. NEXT_PASS (pass_build_ssa); NEXT_PASS (pass_ubsan); NEXT_PASS (pass_early_warn_uninitialized); + NEXT_PASS (pass_nothrow); POP_INSERT_PASSES () NEXT_PASS (pass_chkp_instrumentation_passes); Index: tree-pass.h =================================================================== --- tree-pass.h (revision 221682) +++ tree-pass.h (working copy) @@ -436,6 +436,7 @@ extern gimple_opt_pass *make_pass_remove *ctxt); extern gimple_opt_pass *make_pass_build_cgraph_edges (gcc::context *ctxt); extern gimple_opt_pass *make_pass_local_pure_const (gcc::context *ctxt); +extern gimple_opt_pass *make_pass_nothrow (gcc::context *ctxt); extern gimple_opt_pass *make_pass_tracer (gcc::context *ctxt); extern gimple_opt_pass *make_pass_warn_unused_result (gcc::context *ctxt); extern gimple_opt_pass *make_pass_diagnose_tm_blocks (gcc::context *ctxt); Index: ipa-pure-const.c =================================================================== --- ipa-pure-const.c (revision 221682) +++ ipa-pure-const.c (working copy) @@ -710,6 +711,16 @@ check_stmt (gimple_stmt_iterator *gsip, if (is_gimple_debug (stmt)) return; + /* Do consider clobber as side effects before IPA, so we rather inline + C++ destructors and keep clobber semantics than eliminate them. + + TODO: We may get smarter during early optimizations on these and let + functions containing only clobbers to be optimized more. This is a common + case of C++ destructors. */ + + if ((ipa || cfun->after_inlining) && gimple_clobber_p (stmt)) + return; + if (dump_file) { fprintf (dump_file, " scanning: "); @@ -1870,3 +1881,93 @@ make_pass_warn_function_noreturn (gcc::c { return new pass_warn_function_noreturn (ctxt); } + +/* Simple local pass for pure const discovery reusing the analysis from + ipa_pure_const. This pass is effective when executed together with + other optimization passes in early optimization pass queue. */ + +namespace { + +const pass_data pass_data_nothrow = +{ + GIMPLE_PASS, /* type */ + "nothrow", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_IPA_PURE_CONST, /* tv_id */ + 0, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_nothrow : public gimple_opt_pass +{ +public: + pass_nothrow (gcc::context *ctxt) + : gimple_opt_pass (pass_data_nothrow, ctxt) + {} + + /* opt_pass methods: */ + opt_pass * clone () { return new pass_nothrow (m_ctxt); } + virtual bool gate (function *) { return optimize; } + virtual unsigned int execute (function *); + +}; // class pass_nothrow + +unsigned int +pass_nothrow::execute (function *) +{ + struct cgraph_node *node; + basic_block this_block; + + if (TREE_NOTHROW (current_function_decl)) + return 0; + + node = cgraph_node::get (current_function_decl); + + /* We run during lowering, we can not really use availability yet. */ + if (cgraph_node::get (current_function_decl)->get_availability () + <= AVAIL_INTERPOSABLE) + { + if (dump_file) + fprintf (dump_file, "Function is interposable;" + " not analyzing.\n"); + return true; + } + + FOR_EACH_BB_FN (this_block, cfun) + { + gimple_stmt_iterator gsi; + for (gsi = gsi_start_bb (this_block); + !gsi_end_p (gsi); + gsi_next (&gsi)) + if (stmt_can_throw_external (gsi_stmt (gsi))) + { + tree callee_t = gimple_call_fndecl (gsi_stmt (gsi)); + if (callee_t && recursive_call_p (current_function_decl, callee_t)) + continue; + + if (dump_file) + { + fprintf (dump_file, "Statement can throw: "); + print_gimple_stmt (dump_file, gsi_stmt (gsi), 0, 0); + } + return 0; + } + } + + node->set_nothrow_flag (true); + if (dump_file) + fprintf (dump_file, "Function found to be nothrow: %s\n", + current_function_name ()); + return 0; +} + +} // anon namespace + +gimple_opt_pass * +make_pass_nothrow (gcc::context *ctxt) +{ + return new pass_nothrow (ctxt); +}