From patchwork Thu Mar 29 10:31:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 149382 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]) by ozlabs.org (Postfix) with SMTP id 36281B6ED0 for ; Thu, 29 Mar 2012 21:31:41 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1333621903; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=JNgQWURgacC5TgaNAVjf /LB+HRI=; b=NCwNpcRQBIH2+YoDVxohX5Bd6BjC7OzI1B7cOnXe0epsUmc+Rc+C Mo9zclIzq3f5bQXv5s6SBZUyeAJHd6mzAx8ZQL4UecVTXn+HIibaK25m3rOHotLR kgMSlRrrUNZcJYSW79c85Uzn2ECh41AmwgoCzNbn/wo16IkGQ+6fajY= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=lfyXEWtadZVEKocTEVAZzkZzuVtZk57k6QsrwsVwyiBNtHHuTvUXYKv14eBC2o HN1LtMoVz4GyrL9vjs8Jo2uCnJoVe5lI0Myjdib1t8iJBI8jDgDC0z+GUNPxooxw iEHMv9zGAXGAzJ2LmfKMD47ctUtj1KL0xFS3/ioSAVmxM=; Received: (qmail 10260 invoked by alias); 29 Mar 2012 10:31:35 -0000 Received: (qmail 10245 invoked by uid 22791); 29 Mar 2012 10:31:34 -0000 X-SWARE-Spam-Status: No, hits=-5.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 29 Mar 2012 10:31:20 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 7840393182 for ; Thu, 29 Mar 2012 12:31:19 +0200 (CEST) Date: Thu, 29 Mar 2012 12:31:19 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH][1/n] Cleanup internal interfaces, GCC modularization Message-ID: MIME-Version: 1.0 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 I am playing with doing some internal interface static analysis using the first patch below (and looking at LTO bootstrap results). An example, obvious patch resulting from that is the 2nd patch, resuling from the static analysis output /space/rguenther/src/svn/trunk/gcc/tree-ssa-pre.c:add_to_value can be made static /space/rguenther/src/svn/trunk/gcc/tree-ssa-pre.c:print_value_expressions can be made static the static analysis is very verbose (and does not consider ipa-refs yet). You also need to union results for building all frontends and all targets (well, in theory, or you can simply manually verify things which is a good idea anyway - even unused functions may be useful exported when they implement a generic data structure for example). Excercise for the reader: turn the analysis into a plugin. Richard. 2012-03-29 Richard Guenther * tree-flow.h (struct pre_expr_d): Remove forward declaration. (add_to_value): Remove. (print_value_expressions): Likewise. * tree-ssa-pre.c (add_to_value): Make static. (print_value_expressions): Likewise. Index: gcc/tree-flow.h =================================================================== *** gcc/tree-flow.h (revision 185918) --- gcc/tree-flow.h (working copy) *************** extern bool verify_eh_dispatch_edge (gim *** 794,803 **** extern void maybe_remove_unreachable_handlers (void); /* In tree-ssa-pre.c */ - struct pre_expr_d; - void add_to_value (unsigned int, struct pre_expr_d *); void debug_value_expressions (unsigned int); - void print_value_expressions (FILE *, unsigned int); /* In tree-ssa-sink.c */ bool is_hidden_global_store (gimple); --- 794,800 ---- Index: gcc/tree-ssa-pre.c =================================================================== *** gcc/tree-ssa-pre.c (revision 185918) --- gcc/tree-ssa-pre.c (working copy) *************** phi_trans_add (pre_expr e, pre_expr v, b *** 587,593 **** /* Add expression E to the expression set of value id V. */ ! void add_to_value (unsigned int v, pre_expr e) { bitmap_set_t set; --- 587,593 ---- /* Add expression E to the expression set of value id V. */ ! static void add_to_value (unsigned int v, pre_expr e) { bitmap_set_t set; *************** debug_bitmap_set (bitmap_set_t set) *** 1031,1037 **** /* Print out the expressions that have VAL to OUTFILE. */ ! void print_value_expressions (FILE *outfile, unsigned int val) { bitmap_set_t set = VEC_index (bitmap_set_t, value_expressions, val); --- 1031,1037 ---- /* Print out the expressions that have VAL to OUTFILE. */ ! static void print_value_expressions (FILE *outfile, unsigned int val) { bitmap_set_t set = VEC_index (bitmap_set_t, value_expressions, val); Index: gcc/lto/lto.c =================================================================== --- gcc/lto/lto.c (revision 185918) +++ gcc/lto/lto.c (working copy) @@ -2721,6 +2721,65 @@ read_cgraph_and_symbols (unsigned nfiles lto_symtab_merge_cgraph_nodes (); ggc_collect (); + if (flag_wpa) + { + struct cgraph_node *node; + FILE *f = fopen (concat (dump_base_name, ".callers", NULL), "w"); + for (node = cgraph_nodes; node; node = node->next) + { + tree caller_tu = NULL_TREE; + struct cgraph_edge *caller; + bool found = true; + + if (!TREE_PUBLIC (node->decl) + || !TREE_STATIC (node->decl) + || resolution_used_from_other_file_p (node->resolution)) + continue; + + if (!node->callers) + { + expanded_location loc = expand_location (DECL_SOURCE_LOCATION (node->decl)); + fprintf (f, "%s:%s no calls\n", + loc.file, IDENTIFIER_POINTER (DECL_NAME (node->decl))); + } + for (caller = node->callers; caller; caller = caller->next_caller) + { + if (!caller_tu) + caller_tu = DECL_CONTEXT (caller->caller->decl); + else if (caller_tu + && DECL_CONTEXT (caller->caller->decl) != caller_tu) + found = false; + } + if (found && caller_tu) + { + expanded_location loc1 = expand_location (DECL_SOURCE_LOCATION (node->decl)); + expanded_location loc2 = expand_location (DECL_SOURCE_LOCATION (node->callers->caller->decl)); + + if (DECL_CONTEXT (node->decl) == caller_tu) + fprintf (f, "%s:%s can be made static\n", + loc1.file, IDENTIFIER_POINTER (DECL_NAME (node->decl))); + else + { + struct cgraph_edge *callee; + bool calls_nonpublic_static_fn = false; + /* Check if we can move node to the caller TU without + moving anything else. */ + for (callee = node->callees; callee; callee = callee->next_callee) + { + if (!TREE_PUBLIC (callee->callee->decl) + && TREE_STATIC (callee->callee->decl)) + calls_nonpublic_static_fn = true; + } + if (!calls_nonpublic_static_fn) + fprintf (f, "%s:%s called only from %s\n", + loc1.file, IDENTIFIER_POINTER (DECL_NAME (node->decl)), + loc2.file); + } + } + } + fclose (f); + } + if (flag_ltrans) for (node = cgraph_nodes; node; node = node->next) {