This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How do I set a hard register in gimple
- From: Steve Ellcey <sellcey at imgtec dot com>
- To: Steven Bosscher <stevenb dot gcc at gmail dot com>
- Cc: GCC Mailing List <gcc at gcc dot gnu dot org>
- Date: Wed, 22 Apr 2015 12:27:51 -0700
- Subject: Re: How do I set a hard register in gimple
- Authentication-results: sourceware.org; auth=none
- References: <b48d7c9a-319b-4f4c-aa34-f15634189d80 at BAMAIL02 dot ba dot imgtec dot org> <CABu31nPeOSYdZm+q+xJrmupHydf8iqzv88bYG1VWM2d_5-uH4w at mail dot gmail dot com>
- Reply-to: <sellcey at imgtec dot com>
On Wed, 2015-04-22 at 12:28 +0200, Steven Bosscher wrote:
> This is wrong for sure. You can't have DECL_RTL in GIMPLE.
>
> You will want to set has_local_explicit_reg_vars, DECL_HARD_REGISTER,
> and DECL_ASSEMBLER_NAME, and leave it to the middle end to take care
> of everything else.
>
> Ciao!
> Steven
Thanks for the advice, I switched to DECL_HARD_REGISTER and
DECL_ASSEMBLER_NAME but I am still having the same problem, which is
that the assignment to this global (register) variable is getting
optimized away.
If I have:
ptr_type = build_pointer_type (char_type_node);
id = get_identifier ("X");
ptr_var = build_decl (UNKNOWN_LOCATION, VAR_DECL, id, ptr_type);
TREE_PUBLIC (ptr_var) = 1;
DECL_EXTERNAL (ptr_var) = 1;
varpool_node::finalize_decl (ptr_var);
The the assignment to this global variable is not removed by the
optimizer, which makes sense because someone outside the function could
access the value of the global variable.
But if I change it to:
ptr_type = build_pointer_type (char_type_node);
id = get_identifier ("*$16");
ptr_var = build_decl (UNKNOWN_LOCATION, VAR_DECL, id, ptr_type);
TREE_PUBLIC (ptr_var) = 1;
DECL_EXTERNAL (ptr_var) = 1;
DECL_REGISTER (ptr_var) = 1;
DECL_HARD_REGISTER (ptr_var) = 1;
SET_DECL_ASSEMBLER_NAME (ptr_var, id);
varpool_node::finalize_decl (ptr_var);
Then the assignment to this variable is optimized away by the cse1
optimization phase.
Steve Ellcey
sellcey@imgtec.com