diff mbox

[4/6] Thread pointer built-in functions, s390

Message ID 4FFE743C.7000908@codesourcery.com
State New
Headers show

Commit Message

Chung-Lin Tang July 12, 2012, 6:52 a.m. UTC
S390 parts. In this patch, because the thread-pointer builtins were the
only machine-dependent builtins in the s390 backend, I have removed
basically all the init/expand builtin hook code. If the s390 maintainers
want to keep the code for possible future backend builtins, this patch
might need to be revised.

Also note that __builtin_thread_pointer is now marked as nothrow/const,
and _builtin_set_thread_pointer as nothrow, different from what I saw in
the original s390 code.

Thanks,
Chung-Lin

        * config/s390/s390.c (s390_builtin,code_for_builtin_64,
        code_for_builtin_31,s390_init_builtins,s390_expand_builtin):
        Remove.
        (s390_expand_builtin_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_THREAD_POINTER.
        (s390_expand_builtin_set_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER.

Comments

Andreas Krebbel July 18, 2012, 12:05 p.m. UTC | #1
On 07/12/2012 08:52 AM, Chung-Lin Tang wrote:
>         * config/s390/s390.c (s390_builtin,code_for_builtin_64,
>         code_for_builtin_31,s390_init_builtins,s390_expand_builtin):
>         Remove.
>         (s390_expand_builtin_thread_pointer): Add hook function for
>         TARGET_EXPAND_BUILTIN_THREAD_POINTER.
>         (s390_expand_builtin_set_thread_pointer): Add hook function for
>         TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER.

I've tested your patches on s390x. No regressions.

The patch is ok.

Bye,

-Andreas-
diff mbox

Patch

Index: config/s390/s390.c
===================================================================
--- config/s390/s390.c	(revision 189431)
+++ config/s390/s390.c	(working copy)
@@ -9121,132 +9121,21 @@  s390_gimplify_va_arg (tree valist, tree type, gimp
   return build_va_arg_indirect_ref (addr);
 }
 
-
-/* Builtins.  */
-
-enum s390_builtin
+static rtx
+s390_expand_builtin_thread_pointer (rtx target)
 {
-  S390_BUILTIN_THREAD_POINTER,
-  S390_BUILTIN_SET_THREAD_POINTER,
+  emit_insn (TARGET_64BIT
+	     ? gen_get_tp_64 (target) : gen_get_tp_31 (target));
+  return target;
+}
 
-  S390_BUILTIN_max
-};
-
-static enum insn_code const code_for_builtin_64[S390_BUILTIN_max] = {
-  CODE_FOR_get_tp_64,
-  CODE_FOR_set_tp_64
-};
-
-static enum insn_code const code_for_builtin_31[S390_BUILTIN_max] = {
-  CODE_FOR_get_tp_31,
-  CODE_FOR_set_tp_31
-};
-
 static void
-s390_init_builtins (void)
+s390_expand_builtin_set_thread_pointer (rtx val)
 {
-  tree ftype;
-
-  ftype = build_function_type_list (ptr_type_node, NULL_TREE);
-  add_builtin_function ("__builtin_thread_pointer", ftype,
-			S390_BUILTIN_THREAD_POINTER, BUILT_IN_MD,
-			NULL, NULL_TREE);
-
-  ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
-  add_builtin_function ("__builtin_set_thread_pointer", ftype,
-			S390_BUILTIN_SET_THREAD_POINTER, BUILT_IN_MD,
-			NULL, NULL_TREE);
+  emit_insn (TARGET_64BIT
+	     ? gen_set_tp_64 (val) : gen_set_tp_31 (val));
 }
 
-/* Expand an expression EXP that calls a built-in function,
-   with result going to TARGET if that's convenient
-   (and in mode MODE if that's convenient).
-   SUBTARGET may be used as the target for computing one of EXP's operands.
-   IGNORE is nonzero if the value is to be ignored.  */
-
-static rtx
-s390_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
-		     enum machine_mode mode ATTRIBUTE_UNUSED,
-		     int ignore ATTRIBUTE_UNUSED)
-{
-#define MAX_ARGS 2
-
-  enum insn_code const *code_for_builtin =
-    TARGET_64BIT ? code_for_builtin_64 : code_for_builtin_31;
-
-  tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
-  unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
-  enum insn_code icode;
-  rtx op[MAX_ARGS], pat;
-  int arity;
-  bool nonvoid;
-  tree arg;
-  call_expr_arg_iterator iter;
-
-  if (fcode >= S390_BUILTIN_max)
-    internal_error ("bad builtin fcode");
-  icode = code_for_builtin[fcode];
-  if (icode == 0)
-    internal_error ("bad builtin fcode");
-
-  nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node;
-
-  arity = 0;
-  FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
-    {
-      const struct insn_operand_data *insn_op;
-
-      if (arg == error_mark_node)
-	return NULL_RTX;
-      if (arity > MAX_ARGS)
-	return NULL_RTX;
-
-      insn_op = &insn_data[icode].operand[arity + nonvoid];
-
-      op[arity] = expand_expr (arg, NULL_RTX, insn_op->mode, EXPAND_NORMAL);
-
-      if (!(*insn_op->predicate) (op[arity], insn_op->mode))
-	op[arity] = copy_to_mode_reg (insn_op->mode, op[arity]);
-      arity++;
-    }
-
-  if (nonvoid)
-    {
-      enum machine_mode tmode = insn_data[icode].operand[0].mode;
-      if (!target
-	  || GET_MODE (target) != tmode
-	  || !(*insn_data[icode].operand[0].predicate) (target, tmode))
-	target = gen_reg_rtx (tmode);
-    }
-
-  switch (arity)
-    {
-    case 0:
-      pat = GEN_FCN (icode) (target);
-      break;
-    case 1:
-      if (nonvoid)
-        pat = GEN_FCN (icode) (target, op[0]);
-      else
-	pat = GEN_FCN (icode) (op[0]);
-      break;
-    case 2:
-      pat = GEN_FCN (icode) (target, op[0], op[1]);
-      break;
-    default:
-      gcc_unreachable ();
-    }
-  if (!pat)
-    return NULL_RTX;
-  emit_insn (pat);
-
-  if (nonvoid)
-    return target;
-  else
-    return const0_rtx;
-}
-
-
 /* Output assembly code for the trampoline template to
    stdio stream FILE.
 
@@ -10689,10 +10578,10 @@  s390_loop_unroll_adjust (unsigned nunroll, struct
 #undef TARGET_RETURN_IN_MEMORY
 #define TARGET_RETURN_IN_MEMORY s390_return_in_memory
 
-#undef  TARGET_INIT_BUILTINS
-#define TARGET_INIT_BUILTINS s390_init_builtins
-#undef  TARGET_EXPAND_BUILTIN
-#define TARGET_EXPAND_BUILTIN s390_expand_builtin
+#undef TARGET_EXPAND_BUILTIN_THREAD_POINTER
+#define TARGET_EXPAND_BUILTIN_THREAD_POINTER s390_expand_builtin_thread_pointer
+#undef TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER
+#define TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER s390_expand_builtin_set_thread_pointer
 
 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA s390_output_addr_const_extra