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]

RFC: generate TLS address arithmetic for back-end


Hi folks.

I've been working on adding TLS to the FR-V port.  My work is pretty
much complete, but I've (well Alex) found a possible optimization 
opportunity.

Currently, the back-end never sees address arithmetic of TLS variables
(ala (plus (symbol_ref) (const_int))), because the middle-end avoids
such RTL creation when the address is not a constant.

Since staticp() return FALSE for any TLS addresses, we never generate
the aforementioned RTL.

Some ports could benefit from getting the above RTL (FRV for instance).

Is there a reason for this restriction, or is something like the patch
below the right approach?

Obviously, the patch below would need some cleanups (the predicate
should go in tree.c, and a hook should be added for back-ends wishing
to override this type of arithmetic).

Comments?

	* expr.c (expand_expr): case PLUS_EXPR: Treat TLS address
	arithmetic as a constant.
	(tree_tls_address_p): New.

Index: expr.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/expr.c,v
retrieving revision 1.500.2.1
diff -c -p -r1.500.2.1 expr.c
*** expr.c	28 Nov 2003 21:12:37 -0000	1.500.2.1
--- expr.c	23 Nov 2004 19:02:22 -0000
*************** expand_operands (tree exp0, tree exp1, r
*** 6204,6209 ****
--- 6204,6219 ----
      }
  }
  
+ 
+ /* Return TRUE if ``t'' is an ADDR_EXPR of a thread-local variable.  */
+ bool
+ tree_tls_address_p (tree t)
+ {
+   if (TREE_CODE (t) != ADDR_EXPR)
+     return false;
+   t = TREE_OPERAND (t, 0);
+   return TREE_CODE (t) == VAR_DECL && DECL_THREAD_LOCAL (t);
+ }
  
  /* expand_expr: generate code for computing expression EXP.
     An rtx for the computed value is returned.  The value is never null.
*************** expand_expr (tree exp, rtx target, enum 
*** 7808,7814 ****
  
  	  else if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
  		   && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_INT
! 		   && TREE_CONSTANT (TREE_OPERAND (exp, 0)))
  	    {
  	      rtx constant_part;
  
--- 7818,7825 ----
  
  	  else if (TREE_CODE (TREE_OPERAND (exp, 1)) == INTEGER_CST
  		   && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_INT
! 		   && (TREE_CONSTANT (TREE_OPERAND (exp, 0))
! 		       || tree_tls_address_p (TREE_OPERAND (exp, 0))))
  	    {
  	      rtx constant_part;
  


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