From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 98566 invoked by alias); 18 Dec 2019 11:02:30 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 98555 invoked by uid 89); 18 Dec 2019 11:02:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=H*RU:209.85.208.65, HX-Spam-Relays-External:209.85.208.65, HX-Languages-Length:5177 X-HELO: mail-ed1-f65.google.com Received: from mail-ed1-f65.google.com (HELO mail-ed1-f65.google.com) (209.85.208.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Dec 2019 11:02:28 +0000 Received: by mail-ed1-f65.google.com with SMTP id f8so1308233edv.2 for ; Wed, 18 Dec 2019 03:02:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=vZotng8ndoOBzXkj/iuYZTCQ1Rp5brVjz7CN1ap/wAA=; b=rwexMy0zy8INL3e9Qqde/whXGTu1eB8D66jtSlTdrW2D8nAGf3k90Fvo9HoZYDNU8q JzEVtPyFySERP07qkRiAb1uS6BTQXuZOHq33xp+79Gjab2dr791ggfxRmD/1GtP2G9t3 UQBAQ4TzqhxEJjeEJj/HWDu1k/wyqyRofmQnQA4MRBbvtnlxcdox+Pwpf7bD37QS9lsd IcWxtNd9SM2I0wrA9CKI8oLegmsMrVqpQsq7Hoy/ELih2RkcrzvkCPYbf8bbGe27ZnbB pfB0uaIfdNTjZqTW12ak5SgmnQzvbgRlCJe8VIOSd35UghO5+eOubtamEFav7+AECckT 1Hww== Return-Path: Received: from [192.168.178.32] (x4d0770f2.dyn.telefonica.de. [77.7.112.242]) by smtp.gmail.com with ESMTPSA id r20sm78069eju.60.2019.12.18.03.02.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Dec 2019 03:02:24 -0800 (PST) Date: Wed, 18 Dec 2019 11:02:00 -0000 User-Agent: K-9 Mail for Android In-Reply-To: <88efa85f-66c4-c55a-449a-ac165369a05a@theobroma-systems.com> References: <88efa85f-66c4-c55a-449a-ac165369a05a@theobroma-systems.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: Struct declaration and initialization in TREES To: gcc@gcc.gnu.org,Erick Ochoa ,GCC Development From: Richard Biener Message-ID: <74589E39-B9F2-4F23-B136-0A1B5682B863@gmail.com> X-IsSubscribed: yes X-SW-Source: 2019-12/txt/msg00272.txt.bz2 On December 17, 2019 8:31:00 PM GMT+01:00, Erick Ochoa wrote: >Hi, > >I'm interested in printing VAR_DECL trees that are of type >RECORD_TYPE. I am using the function print_generic_decl >for debugging and found this interesting behaviour. > >When I do initialization of structs using the following >syntax: > >``` >struct aStruct { _Bool e; int a; char b; float c; double d; _Bool f; >long h;}; >struct aStruct astruct =3D { .e =3D 0, .a =3D 1, .b =3D 2, .c =3D 3.0, .d = =3D 4.0, >.f =3D 5, .h =3D 6 }; >``` > >print_generic_decl will print the following output: > >``` >INTERESTED IN: static struct aStruct astruct =3D <<< error >>>; >``` > >Am I using the correct API? Is this a limitation of the API? You need to ask IPA about the static initializer, DECL_INITIAL is adjusted = at some point.=20 Richard.=20 >Would people be interested in me extending this API to print >out something more useful? I already have some code that >iterates over fields and prints out names and types. It >can still use some work though. > >However, I understand if this is the intended behaviour. >Another question (related to the possibility of intended behaviour) >is: how is struct initialization represented in trees? >(I.e. will each field be initialized separately or something else >happens?) > >Thanks! I also include the patch in case people want a simple >working example on how to print declarations. > >diff --git a/gcc/Makefile.in b/gcc/Makefile.in >index 6b857bd..f4f1376 100644 >--- a/gcc/Makefile.in >+++ b/gcc/Makefile.in >@@ -1368,6 +1368,7 @@ OBJS =3D \ > incpath.o \ > init-regs.o \ > internal-fn.o \ >+ ipa-hello-world.o \ > ipa-cp.o \ > ipa-sra.o \ > ipa-devirt.o \ >diff --git a/gcc/common.opt b/gcc/common.opt >index b4dc31c..304ec9f 100644 >--- a/gcc/common.opt >+++ b/gcc/common.opt >@@ -3348,4 +3348,7 @@ fipa-ra > Common Report Var(flag_ipa_ra) Optimization > Use caller save register across calls if possible. >=20 >+fipa-typelist >+Common Report Var(flag_ipa_typelist) TBD >+ > ; This comment is to ensure we retain the blank line above. >diff --git a/gcc/ipa-hello-world.c b/gcc/ipa-hello-world.c >new file mode 100644 >index 0000000..ed4ae11 >--- /dev/null >+++ b/gcc/ipa-hello-world.c >@@ -0,0 +1,78 @@ >+#include "config.h" >+#include "system.h" >+#include "coretypes.h" >+#include "backend.h" >+#include "tree.h" >+#include "gimple-expr.h" >+#include "predict.h" >+#include "alloc-pool.h" >+#include "tree-pass.h" >+#include "cgraph.h" >+#include "diagnostic.h" >+#include "fold-const.h" >+#include "gimple-fold.h" >+#include "symbol-summary.h" >+#include "tree-vrp.h" >+#include "ipa-prop.h" >+#include "tree-pretty-print.h" >+#include "tree-inline.h" >+#include "ipa-fnsummary.h" >+#include "ipa-utils.h" >+#include "tree-ssa-ccp.h" >+#include "stringpool.h" >+#include "attribs.h" >+ >+ >+static unsigned int >+iphw_execute() >+{ >+ if (!dump_file) return 0; >+ varpool_node *node; >+ FOR_EACH_VARIABLE(node) >+ { >+ gcc_assert(node->decl); >+ tree decl =3D node->decl; >+ gcc_assert(TREE_CODE(decl) =3D=3D VAR_DECL); >+ >+ tree curr_type =3D TREE_TYPE(decl); >+ gcc_assert(curr_type); >+ >+ const bool is_struct =3D TREE_CODE(curr_type) =3D=3D RECORD_TYPE; >+ if (is_struct) fprintf(dump_file, "INTERESTED IN: "); >+ print_generic_decl(dump_file, decl, TDF_DETAILS); >+ fprintf(dump_file, "\n"); >+ } >+ return 0; >+} >+ >+namespace { >+const pass_data pass_data_ipa_hello_world =3D >+{ >+ SIMPLE_IPA_PASS, >+ "hello_world", >+ OPTGROUP_NONE, >+ TV_NONE, >+ (PROP_cfg | PROP_ssa), >+ 0, >+ 0, >+ 0, >+ 0, >+}; >+ >+class pass_ipa_hello_world : public simple_ipa_opt_pass >+{ >+public: >+ pass_ipa_hello_world (gcc::context *ctx) >+ : simple_ipa_opt_pass(pass_data_ipa_hello_world, ctx) >+ {} >+ >+ virtual bool gate(function*) { return flag_ipa_typelist; } >+ virtual unsigned execute (function*) { return iphw_execute(); } >+}; >+} // anon namespace >+ >+simple_ipa_opt_pass* >+make_pass_ipa_hello_world (gcc::context *ctx) >+{ >+ return new pass_ipa_hello_world (ctx); >+} >diff --git a/gcc/passes.def b/gcc/passes.def >index 798a391..52cd14b 100644 >--- a/gcc/passes.def >+++ b/gcc/passes.def >@@ -146,6 +146,7 @@ along with GCC; see the file COPYING3. If not see > NEXT_PASS (pass_ipa_profile); > NEXT_PASS (pass_ipa_icf); > NEXT_PASS (pass_ipa_devirt); >+ NEXT_PASS (pass_ipa_hello_world); > NEXT_PASS (pass_ipa_cp); > NEXT_PASS (pass_ipa_sra); > NEXT_PASS (pass_ipa_cdtor_merge); >diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h >index a987661..915fc69 100644 >--- a/gcc/tree-pass.h >+++ b/gcc/tree-pass.h >@@ -498,6 +498,7 @@ extern ipa_opt_pass_d *make_pass_ipa_fn_summary >(gcc::context *ctxt); > extern ipa_opt_pass_d *make_pass_ipa_inline (gcc::context *ctxt); >extern simple_ipa_opt_pass *make_pass_ipa_free_lang_data (gcc::context >*ctxt); >extern simple_ipa_opt_pass *make_pass_ipa_free_fn_summary (gcc::context >*ctxt); >+extern simple_ipa_opt_pass *make_pass_ipa_hello_world (gcc::context >*ctxt); > extern ipa_opt_pass_d *make_pass_ipa_cp (gcc::context *ctxt); > extern ipa_opt_pass_d *make_pass_ipa_sra (gcc::context *ctxt); > extern ipa_opt_pass_d *make_pass_ipa_icf (gcc::context *ctxt);