From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1297 invoked by alias); 16 Dec 2019 23:36:48 -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 1288 invoked by uid 89); 16 Dec 2019 23:36:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=H*f:sk:1f3ca17, H*i:sk:1f3ca17, HX-HELO:sk:mail-vs, D*theobroma-systems.com X-HELO: mail-vs1-f44.google.com Received: from mail-vs1-f44.google.com (HELO mail-vs1-f44.google.com) (209.85.217.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Dec 2019 23:36:46 +0000 Received: by mail-vs1-f44.google.com with SMTP id g23so5304658vsr.7 for ; Mon, 16 Dec 2019 15:36:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4QXG1A4k4uPv90SbCHP1AQ6nPveRYlYUCrffAB+noLo=; b=kAq5yovF7zbFhvBobpYhmiKUNfnjou64al1Nrse8KnVfohR8lVwZqUrLFfFHdM0IEy PV9ThSQ+Sz/vAVA0+mazWJ1uqxUchkhX3BJtQd40HOi5N+A9C8C58jParcf+RJu+LjPS FtsHEIwvrToCiIQVmmVRYiwayZxWRhuz5hYnxRha9NwHACxUxuzxEqhMDj7qNAaOdF34 OeKU7gy5TV38NFKwm3Oi4RSjTF3XFy/6EoAc9BqSGcH5tf24/TwBNUhHEy6M3pCwu9Ho oS8mZ/N1daFEe4Y+alaGECvSUPIvf3gCWJZEjueR923cZ0Mp9gBw8ABpha4FTZeq9GXW HD4g== MIME-Version: 1.0 References: <1f3ca174-f78e-2773-1689-795a6d80b3d4@theobroma-systems.com> In-Reply-To: <1f3ca174-f78e-2773-1689-795a6d80b3d4@theobroma-systems.com> From: Andrew Pinski Date: Mon, 16 Dec 2019 23:36:00 -0000 Message-ID: Subject: Re: Question about struct identifiers after modifications. To: Erick Ochoa Cc: GCC Development , =?UTF-8?Q?Christoph_M=C3=BCllner?= , "Dr. Philipp Tomsich" Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2019-12/txt/msg00260.txt.bz2 On Mon, Dec 16, 2019 at 3:24 PM Erick Ochoa wrote: > > Hello, > > I am working on a struct reorganization optimization pass. > I am able to identify which structs I want to reorganize > and I am also able to create new structs with these modifications. > The way the new structs are generated is the following code > (I am keeping it high-level for conciseness but feel free to ask > for more details). > > static tree > get_sorted_record(tree record) > { > gcc_assert(TREE_CODE(record) == RECORD_TYPE); > log(2, "printing original"); > print_record(record); > tree copy = copy_record(record); > sort_fields_in_place(copy); > log(2, "printing sorted copy"); > print_record(copy); > return copy; > } > > Output: > > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_record(tree):183)printing record aStruct > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)e,boolean_type,8 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)a,integer_type,32 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)b,integer_type,8 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)c,real_type,32 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)d,real_type,64 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)f,boolean_type,8 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)h,integer_type,64 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:tree_node* get_sorted_record(tree):218)printing sorted copy > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_record(tree):183)printing record aStruct > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)e,boolean_type,8 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)b,integer_type,8 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)f,boolean_type,8 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)a,integer_type,32 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)c,real_type,32 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)d,real_type,64 > [log](/home/eochoa/code/gcc/gcc/ipa-hello-world.c:void print_field(tree):199)h,integer_type,64 > > Basically, we copy the tree of structs of interest. > We modify the DECL_CHAIN so that the fields are in the order that > we want. And finally, we would like to replace trees of type `record` > with `copy`. > > At the moment, IDENTIFIER_POINTER for copy and record are the same. > However, I want to keep my design as general as possible. > If I understand correctly, with the current design it is possible > to change all trees of type record with those of type copy. > However, if one wished to change only a subset of these trees, > wouldn't there be a need for a different IDENTIFIER_NODE in clone? > Otherwise, there would be confusion as to how clone and record > differ. (Their IDENTIFIER_POINTERS are the same.) > > So, is the correct way to specialize a type is to modify the > identifier myself or is there an API that allows me to do so? This is what I did: + if (TYPE_NAME (type) != NULL) + { + if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) + tname = IDENTIFIER_POINTER (TYPE_NAME (type)); + else if (DECL_NAME (TYPE_NAME (type)) != NULL) + tname = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); + } ... + char id[10]; + sprintf(id, "%d", i); + if (tname) + { + name = concat (tname, ".reorg.", id, NULL); + TYPE_NAME (newtype[i]) = get_identifier (name); + free (name); + } Where i is the nth new type for the original type. For the fields that have a new type, I did this: + if (nt[1] != NULL && DECL_NAME (fielddecl)) + { + const char *tname = IDENTIFIER_POINTER (DECL_NAME (fielddecl)); + char id[10]; + char *name; + + sprintf(id, "%d", i); + name = concat (tname, ".reorg.", id, NULL); + DECL_NAME (field) = get_identifier (name); + free (name); + } + else + DECL_NAME (field) = DECL_NAME (fielddecl); Where nt was the new types for that field. Thanks, Andrew Pinski > > Thanks!