This is the mail archive of the gcc-patches@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]

New lang hook: ok_for_sibcall


Sibcalls break Java programs in interesting ways.  To fix this while
still allowing sibcalls to be used where it won't hurt, I need to be
able to control when a sibcall is allowed.

Andrew.


2003-05-21  Andrew Haley  <aph@redhat.com>

	* langhooks-def.h (LANG_HOOKS_DECL_OK_FOR_SIBCALL): New.
	(LANG_HOOKS_DECLS): Add LANG_HOOKS_DECL_OK_FOR_SIBCALL.
	(lhd_decl_ok_for_sibcall): New.
	* langhooks.c (lhd_decl_ok_for_sibcall): New.
	* langhooks.h (lang_hooks_for_decls.ok_for_sibcall): New field.
	* calls.c (expand_call): Check lang_hook before generating a
	sibcall.

2003-05-21  Andrew Haley  <aph@redhat.com>

	* lang.c (LANG_HOOKS_DECL_OK_FOR_SIBCALL): New.
	(java_decl_ok_for_sibcall): New.

Index: calls.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/calls.c,v
retrieving revision 1.244.2.7
diff -p -2 -c -r1.244.2.7 calls.c
*** calls.c	22 Apr 2003 15:50:54 -0000	1.244.2.7
--- calls.c	21 May 2003 14:21:05 -0000
*************** expand_call (exp, target, ignore)
*** 2519,2526 ****
        /* If the callee pops its own arguments, then it must pop exactly
  	 the same number of arguments as the current function.  */
!       || RETURN_POPS_ARGS (fndecl, funtype, args_size.constant)
! 	 != RETURN_POPS_ARGS (current_function_decl,
! 			      TREE_TYPE (current_function_decl),
! 			      current_function_args_size))
      try_tail_call = 0;
  
--- 2519,2527 ----
        /* If the callee pops its own arguments, then it must pop exactly
  	 the same number of arguments as the current function.  */
!       || (RETURN_POPS_ARGS (fndecl, funtype, args_size.constant)
! 	  != RETURN_POPS_ARGS (current_function_decl,
! 			       TREE_TYPE (current_function_decl),
! 			       current_function_args_size))
!       || !(*lang_hooks.decls.ok_for_sibcall) (fndecl))
      try_tail_call = 0;
  
Index: langhooks-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks-def.h,v
retrieving revision 1.39.2.2
diff -p -2 -c -r1.39.2.2 langhooks-def.h
*** langhooks-def.h	19 Feb 2003 05:39:28 -0000	1.39.2.2
--- langhooks-def.h	21 May 2003 14:21:05 -0000
*************** extern void lhd_incomplete_type_error PA
*** 65,68 ****
--- 65,69 ----
  extern tree lhd_type_promotes_to PARAMS ((tree));
  extern tree lhd_expr_size PARAMS ((tree));
+ extern bool lhd_decl_ok_for_sibcall PARAMS ((tree));
  
  /* Declarations of default tree inlining hooks.  */
*************** int lhd_tree_dump_type_quals			PARAMS ((
*** 213,216 ****
--- 214,218 ----
  #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL lhd_warn_unused_global_decl
  #define LANG_HOOKS_WRITE_GLOBALS write_global_declarations
+ #define LANG_HOOKS_DECL_OK_FOR_SIBCALL	lhd_decl_ok_for_sibcall
  
  #define LANG_HOOKS_DECLS { \
*************** int lhd_tree_dump_type_quals			PARAMS ((
*** 223,227 ****
    LANG_HOOKS_GETDECLS, \
    LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL, \
!   LANG_HOOKS_WRITE_GLOBALS \
  }
  
--- 225,230 ----
    LANG_HOOKS_GETDECLS, \
    LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL, \
!   LANG_HOOKS_WRITE_GLOBALS, \
!   LANG_HOOKS_DECL_OK_FOR_SIBCALL, \
  }
  
Index: langhooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.c,v
retrieving revision 1.34.4.1
diff -p -2 -c -r1.34.4.1 langhooks.c
*** langhooks.c	19 Feb 2003 05:39:28 -0000	1.34.4.1
--- langhooks.c	21 May 2003 14:21:05 -0000
*************** lhd_expr_size (exp)
*** 444,447 ****
--- 444,457 ----
  }
  
+ /* Return true if decl, which is a function decl, may be called by a
+    sibcall.  */
+ 
+ bool
+ lhd_decl_ok_for_sibcall (decl)
+      tree decl;
+ {
+   return true;
+ }
+ 
  /* lang_hooks.decls.final_write_globals: perform final processing on
     global variables. */
Index: langhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.h,v
retrieving revision 1.48.4.1
diff -p -2 -c -r1.48.4.1 langhooks.h
*** langhooks.h	18 Feb 2003 18:53:20 -0000	1.48.4.1
--- langhooks.h	21 May 2003 14:21:06 -0000
*************** struct lang_hooks_for_decls
*** 172,175 ****
--- 172,178 ----
       of compilation */
    void (*final_write_globals) PARAMS ((void));
+ 
+   /* True if this decl may be called via a sibcall.  */
+   bool (*ok_for_sibcall) PARAMS ((tree));
  };
  
Index: java/lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lang.c,v
retrieving revision 1.114.2.1
diff -p -2 -c -r1.114.2.1 lang.c
*** java/lang.c	5 Jan 2003 15:03:25 -0000	1.114.2.1
--- java/lang.c	21 May 2003 14:21:19 -0000
*************** static bool java_can_use_bit_fields_p PA
*** 78,81 ****
--- 78,82 ----
  static int java_dump_tree PARAMS ((void *, tree));
  static void dump_compound_expr PARAMS ((dump_info_p, tree));
+ static bool java_decl_ok_for_sibcall PARAMS ((tree));
  
  #ifndef TARGET_OBJECT_SUFFIX
*************** struct language_function GTY(())
*** 293,296 ****
--- 294,300 ----
  #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN java_dump_tree
  
+ #undef LANG_HOOKS_DECL_OK_FOR_SIBCALL
+ #define LANG_HOOKS_DECL_OK_FOR_SIBCALL java_decl_ok_for_sibcall
+ 
  /* Each front end provides its own.  */
  const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
*************** java_dump_tree (dump_info, t)
*** 1157,1159 ****
--- 1161,1176 ----
    return 0;
  }
+ 
+ /* Java calls can't, in general, be sibcalls because we need an
+    accurate stack trace in order to guarantee correct operation of
+    methods such as Class.forName(String) and
+    SecurityManager.getClassContext().  */
+ 
+ static bool
+ java_decl_ok_for_sibcall (decl)
+   tree decl;
+ {
+   return DECL_CONTEXT (decl) == current_class;
+ }
+ 
  #include "gt-java-lang.h"


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