This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Where to find global var declaration
- From: Cristina Georgiana Opriceana <cristina dot opriceana at gmail dot com>
- To: David Malcolm <dmalcolm at redhat dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 27 Apr 2016 17:23:07 +0300
- Subject: Re: Where to find global var declaration
- Authentication-results: sourceware.org; auth=none
- References: <CAFA9rWM1AvJ5VA7JpUdfURxZswL1aX57K_E2M5um9q=QDdycMg at mail dot gmail dot com> <1461765291 dot 4417 dot 33 dot camel at redhat dot com>
On Wed, Apr 27, 2016 at 4:54 PM, David Malcolm <dmalcolm@redhat.com> wrote:
> On Wed, 2016-04-27 at 12:34 +0300, Cristina Georgiana Opriceana wrote:
>> Hello,
>>
>> I tried to add a new global declaration of a pointer and I expected
>> to
>> see it in varpool nodes, but it does not appear there.
>>
>> ustackptr = build_decl (UNKNOWN_LOCATION,
>> VAR_DECL, get_identifier ("ustackptr"),
>> build_pointer_type(void_type_node));
>> TREE_ADDRESSABLE (ustackptr) = 1;
>> TREE_USED (ustackptr) = 1;
>> rest_of_decl_compilation (ustackptr, 1, 0);
>>
>> and
>>
>> struct varpool_node *node;
>> FOR_EACH_VARIABLE (node) {
>> fprintf(stdout, "%s\n", get_name(node->decl));
>> }
>
> FWIW, in the the jit "frontend", I wasn't aware of
> rest_of_decl_compilation. Instead I have the following code for
> creating a global variable, which calls varpool_node::get_create and
> varpool_node::finalize_decl directly on the VAR_DECL instance.
>
> That said, maybe rest_of_decl_compilation is the best approach, but I'm
> not sure why it isn't working for you. (I'm not an expert at this, I
> copied from the C frontend and hacked it up till it worked).
>
> This is from gcc/jit/jit-playback.c (which has a family of wrapper classes around "tree", but hopefully the idea is clear):
>
> /* Construct a playback::lvalue instance (wrapping a tree). */
>
> playback::lvalue *
> playback::context::
> new_global (location *loc,
> enum gcc_jit_global_kind kind,
> type *type,
> const char *name)
> {
> gcc_assert (type);
> gcc_assert (name);
> tree inner = build_decl (UNKNOWN_LOCATION, VAR_DECL,
> get_identifier (name),
> type->as_tree ());
> TREE_PUBLIC (inner) = (kind != GCC_JIT_GLOBAL_INTERNAL);
> DECL_COMMON (inner) = 1;
> switch (kind)
> {
> default:
> gcc_unreachable ();
>
> case GCC_JIT_GLOBAL_EXPORTED:
> TREE_STATIC (inner) = 1;
> break;
>
> case GCC_JIT_GLOBAL_INTERNAL:
> TREE_STATIC (inner) = 1;
> break;
>
> case GCC_JIT_GLOBAL_IMPORTED:
> DECL_EXTERNAL (inner) = 1;
> break;
> }
>
> if (loc)
> set_tree_location (inner, loc);
>
> varpool_node::get_create (inner);
>
> varpool_node::finalize_decl (inner);
>
> m_globals.safe_push (inner);
>
> return new lvalue (this, inner);
> }
>
>
> Hope this is helpful
I've checked the rest_of_decl_compilation for your steps and
apparently I missed to set the storage to be static. I thought it
would be automatically set on 1 for global vars.
Thanks!
Cristina
> Dave