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]

How do I set a hard register in gimple


I have a question about inserting code into a function being compiled by
GCC.  Basically I want to set a hard register at the beginning of a 
function like is being done below.  If I compile the program below on MIPS
the $16 register gets set to the result of alloca and even if I optimize
the routine and nothing else uses p ($16), the set of $16 gets done.

register void *p asm ("$16");
void *foo(void *a)
{
	p = alloca(64);
	/* Rest of function.  */
}

But if I try to insert this code myself from inside GCC the setting of $16
keeps getting optimized away and I cannot figure out how to stop it.
My code to set the register does this:

  ptr_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
                        get_identifier ("__alloca_reg"), ptr_type);
  TREE_PUBLIC (ptr_var) = 1;
  DECL_EXTERNAL (ptr_var) = 1;
  SET_DECL_RTL (ptr_var, gen_raw_REG (Pmode, 16));
  DECL_REGISTER (ptr_var) = 1;
  DECL_HARD_REGISTER (ptr_var) = 1;
  TREE_THIS_VOLATILE (ptr_var) = 1;
  TREE_USED (ptr_var) = 1;
  varpool_node::finalize_decl (ptr_var);

  stmt = gimple_build_assign (ptr_var, build_fold_addr_expr (array_var));
  e = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (fun));
  gsi_insert_on_edge_immediate (e, stmt);

And I see the code during the rtl expansion, but during the first CSE
pass the set of $16 goes away.  How do I mark this variable as 'volatile'
so that the assignment to it does not go away?  It must be possible because
the set does not go away in my small example program but I can't figure
out what it is setting that I am not.

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]