Patchwork [5/6] Thread pointer built-in functions, xtensa

login
register
mail settings
Submitter Chung-Lin Tang
Date July 12, 2012, 6:52 a.m.
Message ID <4FFE7445.7020005@codesourcery.com>
Download mbox | patch
Permalink /patch/170582/
State New
Headers show

Comments

Chung-Lin Tang - July 12, 2012, 6:52 a.m.
xtensa parts. No other notes.

Thanks,
Chung-Lin

        * config/xtensa/xtensa.c
        (xtensa_expand_builtin_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_THREAD_POINTER.
        (xtensa_expand_builtin_set_thread_pointer): Add hook function
        for TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER.
        (xtensa_builtin): Remove XTENSA_BUILTIN_THREAD_POINTER and
        XTENSA_BUILTIN_SET_THREAD_POINTER.
        (xtensa_init_builtins): Remove __builtin_thread_pointer,
        __builtin_set_thread_pointer machine-specific builtins.
        (xtensa_fold_builtin): Remove XTENSA_BUILTIN_THREAD_POINTER,
        XTENSA_BUILTIN_SET_THREAD_POINTER cases.
        (xtensa_expand_builtin): Remove XTENSA_BUILTIN_THREAD_POINTER,
        XTENSA_BUILTIN_SET_THREAD_POINTER cases.

Patch

Index: config/xtensa/xtensa.c
===================================================================
--- config/xtensa/xtensa.c	(revision 189431)
+++ config/xtensa/xtensa.c	(working copy)
@@ -158,6 +158,8 @@  static unsigned int xtensa_function_arg_boundary (
 static void xtensa_init_builtins (void);
 static tree xtensa_fold_builtin (tree, int, tree *, bool);
 static rtx xtensa_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
+static rtx xtensa_expand_builtin_thread_pointer (rtx);
+static void xtensa_expand_builtin_set_thread_pointer (rtx);
 static void xtensa_va_start (tree, rtx);
 static bool xtensa_frame_pointer_required (void);
 static rtx xtensa_static_chain (const_tree, bool);
@@ -258,6 +260,13 @@  static const int reg_nonleaf_alloc_order[FIRST_PSE
 #undef  TARGET_EXPAND_BUILTIN
 #define TARGET_EXPAND_BUILTIN xtensa_expand_builtin
 
+#undef TARGET_EXPAND_BUILTIN_THREAD_POINTER
+#define TARGET_EXPAND_BUILTIN_THREAD_POINTER \
+  xtensa_expand_builtin_thread_pointer
+#undef TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER
+#define TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER \
+  xtensa_expand_builtin_set_thread_pointer
+
 #undef  TARGET_PREFERRED_RELOAD_CLASS
 #define TARGET_PREFERRED_RELOAD_CLASS xtensa_preferred_reload_class
 #undef  TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
@@ -3057,8 +3066,6 @@  xtensa_gimplify_va_arg_expr (tree valist, tree typ
 enum xtensa_builtin
 {
   XTENSA_BUILTIN_UMULSIDI3,
-  XTENSA_BUILTIN_THREAD_POINTER,
-  XTENSA_BUILTIN_SET_THREAD_POINTER,
   XTENSA_BUILTIN_max
 };
 
@@ -3077,23 +3084,6 @@  xtensa_init_builtins (void)
 			       "__umulsidi3", NULL_TREE);
   TREE_NOTHROW (decl) = 1;
   TREE_READONLY (decl) = 1;
-
-  if (TARGET_THREADPTR)
-    {
-      ftype = build_function_type_list (ptr_type_node, NULL_TREE);
-      decl = add_builtin_function ("__builtin_thread_pointer", ftype,
-				   XTENSA_BUILTIN_THREAD_POINTER, BUILT_IN_MD,
-				   NULL, NULL_TREE);
-      TREE_READONLY (decl) = 1;
-      TREE_NOTHROW (decl) = 1;
-
-      ftype = build_function_type_list (void_type_node, ptr_type_node,
-					NULL_TREE);
-      decl = add_builtin_function ("__builtin_set_thread_pointer", ftype,
-				   XTENSA_BUILTIN_SET_THREAD_POINTER,
-				   BUILT_IN_MD, NULL, NULL_TREE);
-      TREE_NOTHROW (decl) = 1;
-    }
 }
 
 
@@ -3116,10 +3106,6 @@  xtensa_fold_builtin (tree fndecl, int n_args ATTRI
 			    fold_convert (unsigned_intDI_type_node, arg1));
       break;
 
-    case XTENSA_BUILTIN_THREAD_POINTER:
-    case XTENSA_BUILTIN_SET_THREAD_POINTER:
-      break;
-
     default:
       internal_error ("bad builtin code");
       break;
@@ -3147,25 +3133,25 @@  xtensa_expand_builtin (tree exp, rtx target,
 	 implement it.  If not, just call the function.  */
       return expand_call (exp, target, ignore);
 
-    case XTENSA_BUILTIN_THREAD_POINTER:
-      if (!target || !register_operand (target, Pmode))
-	target = gen_reg_rtx (Pmode);
-      emit_insn (gen_load_tp (target));
-      return target;
-
-    case XTENSA_BUILTIN_SET_THREAD_POINTER:
-      arg = expand_normal (CALL_EXPR_ARG (exp, 0));
-      if (!register_operand (arg, Pmode))
-	arg = copy_to_mode_reg (Pmode, arg);
-      emit_insn (gen_set_tp (arg));
-      return const0_rtx;
-
     default:
       internal_error ("bad builtin code");
     }
   return NULL_RTX;
 }
 
+static rtx
+xtensa_expand_builtin_thread_pointer (rtx target)
+{
+  emit_insn (gen_load_tp (target));
+  return target;
+}
+
+static void
+xtensa_expand_builtin_set_thread_pointer (rtx val)
+{
+  emit_insn (gen_set_tp (val));
+}
+
 /* Worker function for TARGET_PREFERRED_RELOAD_CLASS.  */
 
 static reg_class_t