This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How do I set a hard register in gimple


Following up to my own email, I think I found the missing magic.  I
needed to set global_regs[16] to 1.  Once global_regs was set for the
register, the assignment stopped getting optimized out.

Steve Ellcey
sellcey@imgtec.com


On Wed, 2015-04-22 at 12:27 -0700, Steve Ellcey wrote:
> 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




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]