* Constructing static variables in GIMPLE?
@ 2008-06-13 5:57 Sean Callanan
2008-06-14 20:53 ` Sean Callanan
0 siblings, 1 reply; 2+ messages in thread
From: Sean Callanan @ 2008-06-13 5:57 UTC (permalink / raw)
To: gcc
Dear mailing list:
I am writing GCC code that constructs GIMPLE (after pass_apply_inline
and before pass_all_optimizations) for a function-level static
variable that gets assigned to and passed to another function. My
problem is that I am getting undefined symbol errors for a renamed
version of the symbol.
I define the variable as below:
--
static tree build_static(tree type, const char* name)
{
tree ret = NULL;
ret = build_decl(VAR_DECL, get_identifier(name), type);
DECL_ARTIFICIAL(ret) = 1; // declared by the compiler
DECL_IGNORED_P(ret) = 1; // no debug info
TREE_READONLY(ret) = 0; // writable
DECL_EXTERNAL(ret) = 0; // defined
TREE_STATIC(ret) = 1; // static
TREE_USED(ret) = 1; // used
DECL_CONTEXT(ret) = cfun->decl;
create_var_ann(ret);
add_referenced_var(ret);
return ret;
}
--
Here's an example where I use this function, and demonstrating how I
use the variable.
--
tree last_p = build_static(long_long_unsigned_type_node, "last_p");
// ...
tree subtraction = build2(MINUS_EXPR, long_long_unsigned_type_node,
end_time, start_time);
build_gimple_modify_stmt(last_p, subtraction);
// ...
tree last_p_temp = create_tmp_var(TREE_TYPE(last_p),
get_name(last_p));
tree last_p_name = make_ssa_name(last_p_temp, NULL);
tree last_p_assignment = build_gimple_modify_stmt(last_p_name,
last_p);
SSA_NAME_DEF_STMT(last_p_name) = last_p_assignment;
--
As seen above, I (try to) respect SSA when reading from this variable,
and when assigning to it (I create an SSA_NAME when using the value,
and assign directly to the VAR_DECL). I'm passing an SSA_NAME to the
function. However, when I compile, I'm getting linker errors of the
form:
--
[...]/test.c:4: undefined reference to `last_p.2610'
--
Oddly, I don't get undefined references for `last_p'; I find it very
odd that it's being renamed. Does anyone know what's going on here?
As always, I welcome corrections to my (admittedly novice-level)
GIMPLE- and SSA-fu.
Thanks for looking at this.
Sincerely,
Sean Callanan
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Constructing static variables in GIMPLE?
2008-06-13 5:57 Constructing static variables in GIMPLE? Sean Callanan
@ 2008-06-14 20:53 ` Sean Callanan
0 siblings, 0 replies; 2+ messages in thread
From: Sean Callanan @ 2008-06-14 20:53 UTC (permalink / raw)
To: gcc
Dear mailing list:
I solved my own problem. This is how I construct a static variable:
--
static tree build_static(tree type, const char* name)
{
tree ret = NULL;
ret = build_decl(VAR_DECL, get_identifier(name), type);
TREE_STATIC(ret) = 1;
assemble_variable(ret, 0, 0, 0); // tree decl, int top_level, int
at_end, int dont_output_data
add_referenced_var(ret);
return ret;
}
--
By the way, this only works for static variables; for automatic
variables, this is how I do it:
--
static tree build_automatic(tree type, const char* name)
{
tree ret = NULL;
ret = build_decl(VAR_DECL, get_identifier(name), type);
DECL_ARTIFICIAL(ret) = 1; // declared by the compiler
DECL_IGNORED_P(ret) = 1; // no debug info
TREE_READONLY(ret) = 0; // writable
DECL_EXTERNAL(ret) = 0; // defined
TREE_STATIC(ret) = 0; // automatic
TREE_USED(ret) = 1; // used
DECL_CONTEXT(ret) = cfun->decl;
create_var_ann(ret);
add_referenced_var(ret);
HOST_WIDE_INT decl_size;
if(TYPE_SIZE(type) && TREE_CODE(TYPE_SIZE(type)) == INTEGER_CST)
{
decl_size = tree_low_cst(TYPE_SIZE(type), 0);
}
else
{
decl_size = 0;
}
rtx decl_rtl = assign_stack_local(DECL_MODE(ret), decl_size, 0);
SET_DECL_RTL(ret, decl_rtl);
return ret;
}
--
Sincerely,
Sean Callanan
On Jun 13, 2008, at 1:57 AM, Sean Callanan wrote:
> Dear mailing list:
>
> I am writing GCC code that constructs GIMPLE (after
> pass_apply_inline and before pass_all_optimizations) for a function-
> level static variable that gets assigned to and passed to another
> function. My problem is that I am getting undefined symbol errors
> for a renamed version of the symbol.
> I define the variable as below:
>
> --
> static tree build_static(tree type, const char* name)
> {
> tree ret = NULL;
>
> ret = build_decl(VAR_DECL, get_identifier(name), type);
>
> DECL_ARTIFICIAL(ret) = 1; // declared by the compiler
> DECL_IGNORED_P(ret) = 1; // no debug info
> TREE_READONLY(ret) = 0; // writable
> DECL_EXTERNAL(ret) = 0; // defined
> TREE_STATIC(ret) = 1; // static
> TREE_USED(ret) = 1; // used
> DECL_CONTEXT(ret) = cfun->decl;
>
> create_var_ann(ret);
> add_referenced_var(ret);
>
> return ret;
> }
> --
>
> Here's an example where I use this function, and demonstrating how I
> use the variable.
>
> --
> tree last_p = build_static(long_long_unsigned_type_node, "last_p");
> // ...
> tree subtraction = build2(MINUS_EXPR, long_long_unsigned_type_node,
> end_time, start_time);
> build_gimple_modify_stmt(last_p, subtraction);
> // ...
> tree last_p_temp = create_tmp_var(TREE_TYPE(last_p),
> get_name(last_p));
> tree last_p_name = make_ssa_name(last_p_temp, NULL);
> tree last_p_assignment = build_gimple_modify_stmt(last_p_name,
> last_p);
> SSA_NAME_DEF_STMT(last_p_name) = last_p_assignment;
> --
>
> As seen above, I (try to) respect SSA when reading from this
> variable, and when assigning to it (I create an SSA_NAME when using
> the value, and assign directly to the VAR_DECL). I'm passing an
> SSA_NAME to the function. However, when I compile, I'm getting
> linker errors of the form:
>
> --
> [...]/test.c:4: undefined reference to `last_p.2610'
> --
>
> Oddly, I don't get undefined references for `last_p'; I find it very
> odd that it's being renamed. Does anyone know what's going on
> here? As always, I welcome corrections to my (admittedly novice-
> level) GIMPLE- and SSA-fu.
> Thanks for looking at this.
>
> Sincerely,
> Sean Callanan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-06-14 20:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-13 5:57 Constructing static variables in GIMPLE? Sean Callanan
2008-06-14 20:53 ` Sean Callanan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).