add mips long_call attribute

James E Wilson wilson@specifix.com
Sat Jul 30 01:23:00 GMT 2005


A customer wants to be able to specify that some functions must be long
calls.  Currently, the only way to do this is the -mlong-calls option
which forces all calls to be long calls.  This is overkill.  We can get
the desired result by adding an attribute long_call that does the same
thing as the -mlong-calls option, except one function at a time.  The
ARM and RS6000 ports already have similar attributes.

I have tested this with a mips-elf C and C++ cross compiler build and
make check.  There were no regressions.  I also tested the doc change
with make info and make dvi.

I'll wait a few days in case a MIPS maintainer wants to comment, then I
plan to check it in.
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com
-------------- next part --------------
2005-07-28  James E Wilson  <wilson@specifixinc.com>

	* config/mips/mips.c (mips_encode_section_info, mips_attribute_table,
	TARGET_ENCODE_SECTION_INFO, TARGET_ATTRIBUTE_TABLE): New.
	* config/mips/mips.h (SYMBOL_FLAG_LONG_CALL, SYMBOL_REF_LONG_CALL_P):
	New.
	* config/mips/predicates.md (const_call_insn_operand): Add check for
	SYMBOL_REF_LONG_CALL_P.
	* doc/extend.texi (long_call): Document the new attribute.

Index: config/mips/mips.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.c,v
retrieving revision 1.517
diff -p -p -r1.517 mips.c
*** config/mips/mips.c	23 Jul 2005 08:36:52 -0000	1.517
--- config/mips/mips.c	30 Jul 2005 01:06:10 -0000
*************** static rtx mips_expand_builtin_compare (
*** 406,411 ****
--- 406,412 ----
  					enum insn_code, enum mips_fp_condition,
  					rtx, tree);
  static rtx mips_expand_builtin_bposge (enum mips_builtin_type, rtx);
+ static void mips_encode_section_info (tree, rtx, int);
  
  /* Structure to be filled in by compute_frame_size with register
     save masks, and offsets for the current function.  */
*************** const enum reg_class mips_regno_to_class
*** 689,694 ****
--- 690,702 ----
  
  /* Map register constraint character to register class.  */
  enum reg_class mips_char_to_class[256];
+ 
+ /* Table of machine dependent attributes.  */
+ const struct attribute_spec mips_attribute_table[] =
+ {
+   { "long_call",   0, 0, false, true,  true,  NULL },
+   { NULL,	   0, 0, false, false, false, NULL }
+ };
  
  /* A table describing all the processors gcc knows about.  Names are
     matched in the order listed.  The first mention of an ISA level is
*************** static struct mips_rtx_cost_data const m
*** 1126,1131 ****
--- 1134,1145 ----
  #undef TARGET_CANNOT_FORCE_CONST_MEM
  #define TARGET_CANNOT_FORCE_CONST_MEM mips_cannot_force_const_mem
  
+ #undef TARGET_ENCODE_SECTION_INFO
+ #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info
+ 
+ #undef TARGET_ATTRIBUTE_TABLE
+ #define TARGET_ATTRIBUTE_TABLE mips_attribute_table
+ 
  struct gcc_target targetm = TARGET_INITIALIZER;
  
  /* Classify symbol X, which must be a SYMBOL_REF or a LABEL_REF.  */
*************** mips_expand_builtin_bposge (enum mips_bu
*** 10699,10702 ****
--- 10713,10732 ----
    return target;
  }
  
+ /* Set SYMBOL_REF_FLAGS for the SYMBOL_REF inside RTL, which belongs to DECL.
+    FIRST is true if this is the first time handling this decl.  */
+ 
+ static void
+ mips_encode_section_info (tree decl, rtx rtl, int first)
+ {
+   default_encode_section_info (decl, rtl, first);
+ 
+   if (TREE_CODE (decl) == FUNCTION_DECL
+       && lookup_attribute ("long_call", TYPE_ATTRIBUTES (TREE_TYPE (decl))))
+     {
+       rtx symbol = XEXP (rtl, 0);
+       SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LONG_CALL;
+     }
+ }
+ 
  #include "gt-mips.h"
Index: config/mips/mips.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.h,v
retrieving revision 1.400
diff -p -p -r1.400 mips.h
*** config/mips/mips.h	23 Jul 2005 08:36:53 -0000	1.400
--- config/mips/mips.h	30 Jul 2005 01:06:11 -0000
*************** typedef struct mips_args {
*** 2300,2305 ****
--- 2300,2310 ----
    else									\
      asm_fprintf ((FILE), "%U%s", (NAME))
  
+ /* Flag to mark a function decl symbol that requires a long call.  */
+ #define SYMBOL_FLAG_LONG_CALL	(SYMBOL_FLAG_MACH_DEP << 0)
+ #define SYMBOL_REF_LONG_CALL_P(X)					\
+   ((SYMBOL_REF_FLAGS (X) & SYMBOL_FLAG_LONG_CALL) != 0)
+ 
  /* Specify the machine mode that this machine uses
     for the index in the tablejump instruction.
     ??? Using HImode in mips16 mode can cause overflow.  */
Index: config/mips/predicates.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/predicates.md,v
retrieving revision 1.8
diff -p -p -r1.8 predicates.md
*** config/mips/predicates.md	23 Jul 2005 08:36:54 -0000	1.8
--- config/mips/predicates.md	30 Jul 2005 01:06:11 -0000
***************
*** 103,110 ****
    switch (symbol_type)
      {
      case SYMBOL_GENERAL:
!       /* If -mlong-calls, force all calls to use register addressing.  */
!       return !TARGET_LONG_CALLS;
  
      case SYMBOL_GOT_GLOBAL:
        /* Without explicit relocs, there is no special syntax for
--- 103,112 ----
    switch (symbol_type)
      {
      case SYMBOL_GENERAL:
!       /* If -mlong-calls, force all calls to use register addressing.  Also,
! 	 if this function has the long_call attribute, we must use register
! 	 addressing.  */
!       return !TARGET_LONG_CALLS && !SYMBOL_REF_LONG_CALL_P (op);
  
      case SYMBOL_GOT_GLOBAL:
        /* Without explicit relocs, there is no special syntax for
Index: doc/extend.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/extend.texi,v
retrieving revision 1.262
diff -p -p -r1.262 extend.texi
*** doc/extend.texi	23 Jul 2005 08:36:43 -0000	1.262
--- doc/extend.texi	30 Jul 2005 01:06:09 -0000
*************** both the @option{-mlongcall} switch and,
*** 1942,1947 ****
--- 1942,1955 ----
  @xref{RS/6000 and PowerPC Options}, for more information on whether long
  calls are necessary.
  
+ @item long_call
+ @cindex indirect calls on MIPS
+ This attribute specifies how a particular function is called on MIPS@.
+ The attribute overrides the @option{-mlong-calls} (@pxref{MIPS Options})
+ command line switch.  This attribute causes the compiler to always call
+ the function by first loading its address into a register, and then using
+ the contents of that register.
+ 
  @item malloc
  @cindex @code{malloc} attribute
  The @code{malloc} attribute is used to tell the compiler that a function


More information about the Gcc-patches mailing list