From patchwork Thu May 18 15:08:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 764040 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 3wTF2W6B0Vz9s5j for ; Fri, 19 May 2017 01:09:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Ojj24sT1"; 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 :subject:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=K+lYPOQv/YktJ67fk VlGwt5PJ4md6W2oov1fT5GKdacJjWOSwwcJWMuFxUUAxyw22imLIYEkBdsuHh/T1 0ZZ3gCTjrqaljKZX74PPJnu4x7x4vrMMgkhhlWQ+9NZG7PbFN0UUr0ArpFAtfLQp H/r4XWANUFgTLnXnE5SBLn/v2Q= 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 :subject:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=VGSvVUMfFPNr0NPVr7aK3bT FCp0=; b=Ojj24sT1h6Vu/bBmcF+gbhuizshOL0VHMIspt30vHpft2QrXZsTrtTp tikzt/V1UDneNXneLvlWYe8yWAe5MbvKnPXu+eZMHXFBe6X+bJ8fGOHWXSssRuk9 8cTjRfJRoPmgcOIrnx6AiNal2E5KPtXmeN4teOUB73RvNUctfLr8= Received: (qmail 47283 invoked by alias); 18 May 2017 15:08:55 -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 47273 invoked by uid 89); 18 May 2017 15:08:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy=portions, 10969 X-HELO: mail-yw0-f178.google.com Received: from mail-yw0-f178.google.com (HELO mail-yw0-f178.google.com) (209.85.161.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 May 2017 15:08:51 +0000 Received: by mail-yw0-f178.google.com with SMTP id b68so22239113ywe.3 for ; Thu, 18 May 2017 08:08:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:references:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=F/bmdbkMBRRo7TAi9mf16viV6esshtakzqsF7YMeCQ4=; b=drwzTY4MsW0c8N1a0ylcylnwpoDKiWLccqfrrY7tj0NdVuP7OowdUTZw5q/1AYeYVU kpR/p5YnAkzpKlVZECSSciMYG/goV3AaPVA2uecSad3TYd5nSpSbCdOqod+MYxlYKtO7 4Aw7LrrpF7iCh9977xeTbpJRL9/8eaQWZHO2JQXW0mzTYvxZiy5dlrsVz8WRcnYLWbnc MvKK+Z8PEmrzTb3WfAktHQY4WVjqmDiljNrupNXxW6ityOnLhtgrhW+S1XrDl4ZdEy5F QMI7WZeGjMsriNJnWmdfQMVNNQwl2lOqdEAO7eTa2WCxO9QYhphTmDy0c/5kya2Ejnd4 EJbQ== X-Gm-Message-State: AODbwcDLsXApa/PpC+5/4B8EpjhB280S8wqGOba1OMc8HvcQ0rJgcRRX uiAX5I2+gadj9w== X-Received: by 10.129.117.135 with SMTP id q129mr3745557ywc.220.1495120133402; Thu, 18 May 2017 08:08:53 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::7:4a1a]) by smtp.googlemail.com with ESMTPSA id v77sm2497505ywc.6.2017.05.18.08.08.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 08:08:53 -0700 (PDT) Subject: Re: [PATCH] gcc::context creation From: Nathan Sidwell To: GCC Patches , Richard Biener Cc: =?UTF-8?Q?Martin_Li=c5=a1ka?= References: <7f7f64a5-f820-a19a-d4ea-77b05f746499@acm.org> Message-ID: <98b0273e-9390-18ce-c041-31f843b8b1f8@acm.org> Date: Thu, 18 May 2017 11:08:51 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: <7f7f64a5-f820-a19a-d4ea-77b05f746499@acm.org> On 05/16/2017 11:26 AM, Nathan Sidwell wrote: > This patch breaks apart the creation of the pass manager from > gcc::context's ctor. This will allow us to register additional dumps ... https://gcc.gnu.org/ml/gcc-patches/2017-05/msg01295.html This patch builds upon the context creation patch (this diff includes it), to implement a new LANG_HOOK_REGISTER_DUMPS language hook. I call it between creating the dump manager and instantiating the optimization passes. The patch then uses the hook to move the current -fdump-class-hierarchy option into the C++ FE entirely, removing TDI_class and associated handling from dumpfile and c-family/c-opts.c. The option gets renamed to -fdump-lang-class in the process. Obviously -fdump-translation-unit is the next candidate, and possibly -fdump-tree-original. ok? nathan 2017-05-18 Nathan Sidwell LANG_HOOK_REGISTER_DUMPS gcc/ * context.h (context::set_passes): New. * context.c (context::context): Do not create pass manager. * toplev.c (general_init): Create pass manager here. Call register dump lang hook. * doc/invoke.texi: Document -fdump-lang option family. * dumpfile.c (dump_files): Remove class dump here. (FIRST_AUTO_NUMBERED_DUMP): Adjust. * dumpfile.h (tree_dump_index): Remove TDI_class. * langhooks-def.h (lhd_register_dumps): Declare. (LANG_HOOKS_REGISTER_DUMPS): Define. (LANG_HOOKS_INITIALIZER): Add it. * langhooks.c (lhd_register_dumps): Define. * langhooks.h (struct lang_hooks): Add register_dumps. c-family/ * c-opts.c (class_dump_file, class_dump_flags): Delete. (c_common_parse_file): Remove class dump handling. (get_dump_info): Likewise. cp/ * class.c (class_dump_id): Define. (dump_class_hierarchy, dump_vtable, dump_vtt): Use it. * cp-objcp-common.c (cp_register_dumps): New. * cp-objcp-common.h (cp_register_dumps): Declare. (LANG_HOOKS_REGISTER_DUMPS): Override. * cp-tree.h (class_dump_id): Declare. testsuite/ * g++.dg/inherit/covariant7.C: Adjust. Index: c-family/c-opts.c =================================================================== --- c-family/c-opts.c (revision 248195) +++ c-family/c-opts.c (working copy) @@ -102,8 +102,6 @@ static size_t include_cursor; /* Dump files/flags to use during parsing. */ static FILE *original_dump_file = NULL; static dump_flags_t original_dump_flags; -static FILE *class_dump_file = NULL; -static dump_flags_t class_dump_flags; /* Whether any standard preincluded header has been preincluded. */ static bool done_preinclude; @@ -1098,10 +1096,9 @@ c_common_parse_file (void) for (;;) { c_finish_options (); - /* Open the dump files to use for the original and class dump output + /* Open the dump file to use for the original dump output here, to be used during parsing for the current file. */ original_dump_file = dump_begin (TDI_original, &original_dump_flags); - class_dump_file = dump_begin (TDI_class, &class_dump_flags); pch_init (); push_file_scope (); c_parse_file (); @@ -1120,11 +1117,6 @@ c_common_parse_file (void) dump_end (TDI_original, original_dump_file); original_dump_file = NULL; } - if (class_dump_file) - { - dump_end (TDI_class, class_dump_file); - class_dump_file = NULL; - } /* If an input file is missing, abandon further compilation. cpplib has issued a diagnostic. */ if (!this_input_filename) @@ -1135,20 +1127,14 @@ c_common_parse_file (void) } /* Returns the appropriate dump file for PHASE to dump with FLAGS. */ + FILE * get_dump_info (int phase, dump_flags_t *flags) { - gcc_assert (phase == TDI_original || phase == TDI_class); - if (phase == TDI_original) - { - *flags = original_dump_flags; - return original_dump_file; - } - else - { - *flags = class_dump_flags; - return class_dump_file; - } + gcc_assert (phase == TDI_original); + + *flags = original_dump_flags; + return original_dump_file; } /* Common finish hook for the C, ObjC and C++ front ends. */ Index: context.c =================================================================== --- context.c (revision 248195) +++ context.c (working copy) @@ -29,14 +29,9 @@ along with GCC; see the file COPYING3. gcc::context *g; gcc::context::context () + : m_passes (NULL), m_dumps (new gcc::dump_manager ()) { have_offload = false; - - /* The pass manager's constructor uses the dump manager (to set up - dumps for the various passes), so the dump manager must be set up - before the pass manager. */ - m_dumps = new gcc::dump_manager (); - m_passes = new gcc::pass_manager (this); } gcc::context::~context () Index: context.h =================================================================== --- context.h (revision 248195) +++ context.h (working copy) @@ -39,6 +39,12 @@ public: /* Pass-management. */ + void set_passes (pass_manager *m) + { + gcc_assert (!m_passes); + m_passes = m; + } + pass_manager *get_passes () { gcc_assert (m_passes); return m_passes; } /* Handling dump files. */ Index: cp/class.c =================================================================== --- cp/class.c (revision 248195) +++ cp/class.c (working copy) @@ -37,6 +37,9 @@ along with GCC; see the file COPYING3. #include "gimplify.h" #include "intl.h" +/* Id for dumping the class heirarchy. */ +int class_dump_id; + /* The number of nested classes being processed. If we are not in the scope of any class, this is zero. */ @@ -8914,11 +8917,10 @@ static void dump_class_hierarchy (tree t) { dump_flags_t flags; - FILE *stream = get_dump_info (TDI_class, &flags); - - if (stream) + if (FILE *stream = dump_begin (class_dump_id, &flags)) { dump_class_hierarchy_1 (stream, flags, t); + dump_end (class_dump_id, stream); } } @@ -8948,7 +8950,7 @@ static void dump_vtable (tree t, tree binfo, tree vtable) { dump_flags_t flags; - FILE *stream = get_dump_info (TDI_class, &flags); + FILE *stream = dump_begin (class_dump_id, &flags); if (!stream) return; @@ -8971,13 +8973,15 @@ dump_vtable (tree t, tree binfo, tree vt dump_array (stream, vtable); fprintf (stream, "\n"); } + + dump_end (class_dump_id, stream); } static void dump_vtt (tree t, tree vtt) { dump_flags_t flags; - FILE *stream = get_dump_info (TDI_class, &flags); + FILE *stream = dump_begin (class_dump_id, &flags); if (!stream) return; @@ -8989,6 +8993,8 @@ dump_vtt (tree t, tree vtt) dump_array (stream, vtt); fprintf (stream, "\n"); } + + dump_end (class_dump_id, stream); } /* Dump a function or thunk and its thunkees. */ Index: cp/cp-objcp-common.c =================================================================== --- cp/cp-objcp-common.c (revision 248195) +++ cp/cp-objcp-common.c (working copy) @@ -352,6 +352,15 @@ cp_pushdecl (tree decl) return pushdecl (decl); } +/* Register c++-specific dumps. */ + +void +cp_register_dumps (gcc::dump_manager *dumps) +{ + class_dump_id = dumps->dump_register + (".class", "lang-class", "lang-class", TDF_LANG, OPTGROUP_NONE, false); +} + void cp_common_init_ts (void) { Index: cp/cp-objcp-common.h =================================================================== --- cp/cp-objcp-common.h (revision 248195) +++ cp/cp-objcp-common.h (working copy) @@ -33,6 +33,7 @@ extern void cp_common_init_ts (void); extern tree cp_unit_size_without_reusable_padding (tree); extern tree cp_get_global_decls (); extern tree cp_pushdecl (tree); +extern void cp_register_dumps (gcc::dump_manager *); /* Lang hooks that are shared between C++ and ObjC++ are defined here. Hooks specific to C++ or ObjC++ go in cp/cp-lang.c and objcp/objcp-lang.c, @@ -56,6 +57,8 @@ extern tree cp_pushdecl (tree); #define LANG_HOOKS_INIT_OPTIONS c_common_init_options #undef LANG_HOOKS_INITIALIZE_DIAGNOSTICS #define LANG_HOOKS_INITIALIZE_DIAGNOSTICS cxx_initialize_diagnostics +#undef LANG_HOOKS_REGISTER_DUMPS +#define LANG_HOOKS_REGISTER_DUMPS cp_register_dumps #undef LANG_HOOKS_HANDLE_OPTION #define LANG_HOOKS_HANDLE_OPTION c_common_handle_option #undef LANG_HOOKS_HANDLE_FILENAME Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 248195) +++ cp/cp-tree.h (working copy) @@ -5752,6 +5752,9 @@ concept_template_p (tree t) e.g "int f(void)". */ extern cp_parameter_declarator *no_parameters; +/* Various dump ids. */ +extern int class_dump_id; + /* in call.c */ extern bool check_dtor_name (tree, tree); int magic_varargs_p (tree); Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 248195) +++ doc/invoke.texi (working copy) @@ -544,6 +544,9 @@ Objective-C and Objective-C++ Dialects}. -fdump-final-insns@r{[}=@var{file}@r{]} -fdump-ipa-all -fdump-ipa-cgraph -fdump-ipa-inline @gol -fdump-lang-all @gol +-fdump-lang-@var{switch} @gol +-fdump-lang-@var{switch}-@var{options} @gol +-fdump-lang-@var{switch}-@var{options}=@var{filename} @gol -fdump-passes @gol -fdump-rtl-@var{pass} -fdump-rtl-@var{pass}=@var{filename} @gol -fdump-statistics @gol @@ -12940,16 +12943,6 @@ When doing debugging dumps (see @option{ instruction numbers for the links to the previous and next instructions in a sequence. -@item -fdump-class-hierarchy @r{(C++ only)} -@itemx -fdump-class-hierarchy-@var{options} @r{(C++ only)} -@opindex fdump-class-hierarchy -Dump a representation of each class's hierarchy and virtual function -table layout to a file. The file name is made by appending -@file{.class} to the source file name, and the file is created in the -same directory as the output file. If the @samp{-@var{options}} form -is used, @var{options} controls the details of the dump as described -for the @option{-fdump-tree} options. - @item -fdump-ipa-@var{switch} @opindex fdump-ipa Control the dumping at various stages of inter-procedural analysis @@ -12972,8 +12965,26 @@ Dump after function inlining. @end table @item -fdump-lang-all +@itemx -fdump-lang-@var{switch} +@itemx -fdump-lang-@var{switch}-@var{options} +@itemx -fdump-lang-@var{switch}-@var{options}=@var{filename} @opindex fdump-lang-all -Control the dumping of language-specific information. +@opindex fdump-lang +Control the dumping of language-specific information. The @var{options} +and @var{filename} portions behave as described in the +`@option{-fdump-tree} option. The following @var{switch} values are +accepted: + +@table @samp +@item all + +Enable all language-specific dumps. + +@item class +Dump class heirarchy information. Virtual table information is emitted +unless '@option{slim}' is specified. This option is applicable to C++ only. + +@end table @item -fdump-passes @opindex fdump-passes Index: dumpfile.c =================================================================== --- dumpfile.c (revision 248195) +++ dumpfile.c (working copy) @@ -60,15 +60,13 @@ static struct dump_file_info dump_files[ 0, 0, 0, 0, 0, false, false}, {".tu", "translation-unit", NULL, NULL, NULL, NULL, NULL, TDF_LANG, 0, 0, 0, 0, 1, false, false}, - {".class", "class-hierarchy", NULL, NULL, NULL, NULL, NULL, TDF_LANG, - 0, 0, 0, 0, 2, false, false}, {".original", "tree-original", NULL, NULL, NULL, NULL, NULL, TDF_TREE, 0, 0, 0, 0, 3, false, false}, {".gimple", "tree-gimple", NULL, NULL, NULL, NULL, NULL, TDF_TREE, 0, 0, 0, 0, 4, false, false}, {".nested", "tree-nested", NULL, NULL, NULL, NULL, NULL, TDF_TREE, 0, 0, 0, 0, 5, false, false}, -#define FIRST_AUTO_NUMBERED_DUMP 6 +#define FIRST_AUTO_NUMBERED_DUMP 5 {NULL, "lang-all", NULL, NULL, NULL, NULL, NULL, TDF_LANG, 0, 0, 0, 0, 0, false, false}, Index: dumpfile.h =================================================================== --- dumpfile.h (revision 248195) +++ dumpfile.h (working copy) @@ -31,7 +31,6 @@ enum tree_dump_index TDI_inheritance, /* dump type inheritance graph. */ TDI_clones, /* dump IPA cloning decisions. */ TDI_tu, /* dump the whole translation unit. */ - TDI_class, /* dump class hierarchy. */ TDI_original, /* dump each function before optimizing it */ TDI_generic, /* dump each function after genericizing it */ TDI_nested, /* dump each function after unnesting it */ Index: langhooks-def.h =================================================================== --- langhooks-def.h (revision 248195) +++ langhooks-def.h (working copy) @@ -39,6 +39,7 @@ extern void lhd_do_nothing (void); extern void lhd_do_nothing_t (tree); extern void lhd_do_nothing_f (struct function *); extern tree lhd_pass_through_t (tree); +extern void lhd_register_dumps (gcc::dump_manager *); extern bool lhd_post_options (const char **); extern alias_set_type lhd_get_alias_set (tree); extern tree lhd_return_null_tree (tree); @@ -97,6 +98,7 @@ extern int lhd_type_dwarf_attribute (con #define LANG_HOOKS_INIT_OPTIONS_STRUCT hook_void_gcc_optionsp #define LANG_HOOKS_INIT_OPTIONS lhd_init_options #define LANG_HOOKS_INITIALIZE_DIAGNOSTICS lhd_initialize_diagnostics +#define LANG_HOOKS_REGISTER_DUMPS lhd_register_dumps #define LANG_HOOKS_COMPLAIN_WRONG_LANG_P lhd_complain_wrong_lang_p #define LANG_HOOKS_HANDLE_OPTION lhd_handle_option #define LANG_HOOKS_POST_OPTIONS lhd_post_options @@ -294,6 +296,7 @@ extern void lhd_end_section (void); LANG_HOOKS_INIT_OPTIONS_STRUCT, \ LANG_HOOKS_INIT_OPTIONS, \ LANG_HOOKS_INITIALIZE_DIAGNOSTICS, \ + LANG_HOOKS_REGISTER_DUMPS, \ LANG_HOOKS_COMPLAIN_WRONG_LANG_P, \ LANG_HOOKS_HANDLE_OPTION, \ LANG_HOOKS_POST_OPTIONS, \ Index: langhooks.c =================================================================== --- langhooks.c (revision 248195) +++ langhooks.c (working copy) @@ -322,6 +322,12 @@ lhd_initialize_diagnostics (diagnostic_c { } +/* Called to register dumps. */ +void +lhd_register_dumps (gcc::dump_manager *) +{ +} + /* Called to perform language-specific options initialization. */ void lhd_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED, Index: langhooks.h =================================================================== --- langhooks.h (revision 248195) +++ langhooks.h (working copy) @@ -326,6 +326,9 @@ struct lang_hooks global diagnostic context structure. */ void (*initialize_diagnostics) (diagnostic_context *); + /* Register language-specific dumps. */ + void (*register_dumps) (gcc::dump_manager *); + /* Return true if a warning should be given about option OPTION, which is for the wrong language, false if it should be quietly ignored. */ Index: testsuite/g++.dg/inherit/covariant7.C =================================================================== --- testsuite/g++.dg/inherit/covariant7.C (revision 248195) +++ testsuite/g++.dg/inherit/covariant7.C (working copy) @@ -1,6 +1,6 @@ // { dg-do compile } // { dg-prune-output "direct base" } -// { dg-options "-fdump-class-hierarchy" } +// { dg-options "-fdump-lang-class" } // Copyright (C) 2002 Free Software Foundation, Inc. // Contributed by Nathan Sidwell 27 Dec 2002 Index: toplev.c =================================================================== --- toplev.c (revision 248195) +++ toplev.c (working copy) @@ -1154,9 +1154,17 @@ general_init (const char *argv0, bool in processing. */ init_ggc_heuristics (); - /* Create the singleton holder for global state. - Doing so also creates the pass manager and with it the passes. */ + /* Create the singleton holder for global state. This creates the + dump manager. */ g = new gcc::context (); + + /* Allow languages to register their dumps before the optimization + passes. */ + lang_hooks.register_dumps (g->get_dumps ()); + + /* Create the passes. */ + g->set_passes (new gcc::pass_manager (g)); + symtab = new (ggc_cleared_alloc ()) symbol_table (); statistics_early_init ();