Finally, what I personally need, the MIPS parts.

Thanks,
Chung-Lin

        * config/mips/mips.c (mips_get_tp): Add 'target' parameter for
        generating to specific reg.
        (mips_legitimize_tls_address): Update calls to mips_get_tp().
        (mips_expand_builtin_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_THREAD_POINTER.
Index: config/mips/mips.c
===================================================================
--- config/mips/mips.c  (revision 189431)
+++ config/mips/mips.c  (working copy)
@@ -2851,11 +2851,12 @@ mips_call_tls_get_addr (rtx sym, enum mips_symbol_
 /* Return a pseudo register that contains the current thread pointer.  */
 
 static rtx
-mips_get_tp (void)
+mips_get_tp (rtx target)
 {
-  rtx tp, fn;
+  rtx fn;
+  rtx tp = (target != NULL_RTX && REG_P (target)
+           ? target : gen_reg_rtx (Pmode));
 
-  tp = gen_reg_rtx (Pmode);
   if (TARGET_MIPS16)
     {
       mips_need_mips16_rdhwr_p = true;
@@ -2919,7 +2920,7 @@ mips_legitimize_tls_address (rtx loc)
       break;
 
     case TLS_MODEL_INITIAL_EXEC:
-      tp = mips_get_tp ();
+      tp = mips_get_tp (NULL_RTX);
       tmp1 = gen_reg_rtx (Pmode);
       tmp2 = mips_unspec_address (loc, SYMBOL_GOTTPREL);
       if (Pmode == DImode)
@@ -2931,7 +2932,7 @@ mips_legitimize_tls_address (rtx loc)
       break;
 
     case TLS_MODEL_LOCAL_EXEC:
-      tmp1 = mips_get_tp ();
+      tmp1 = mips_get_tp (NULL_RTX);
       offset = mips_unspec_address (loc, SYMBOL_TPREL);
       if (mips_split_p[SYMBOL_TPREL])
        {
@@ -13884,6 +13885,13 @@ mips_expand_builtin (tree exp, rtx target, rtx sub
     }
   gcc_unreachable ();
 }
+
+static rtx
+mips_expand_builtin_thread_pointer (rtx target)
+{
+  return mips_get_tp (target);
+}
+
 
 /* An entry in the MIPS16 constant pool.  VALUE is the pool constant,
    MODE is its mode, and LABEL is the CODE_LABEL associated with it.  */
@@ -17567,6 +17575,10 @@ mips_expand_vec_minmax (rtx target, rtx op0, rtx o
 #undef TARGET_EXPAND_BUILTIN
 #define TARGET_EXPAND_BUILTIN mips_expand_builtin
 
+#undef TARGET_EXPAND_BUILTIN_THREAD_POINTER
+#define TARGET_EXPAND_BUILTIN_THREAD_POINTER \
+  mips_expand_builtin_thread_pointer
+
 #undef TARGET_HAVE_TLS
 #define TARGET_HAVE_TLS HAVE_AS_TLS
 

Reply via email to