allow the target to label code fragments generated by partitioning.
authorIain Sandoe <iains@gcc.gnu.org>
Fri, 7 Jan 2011 13:57:45 +0000 (13:57 +0000)
committerIain Sandoe <iains@gcc.gnu.org>
Fri, 7 Jan 2011 13:57:45 +0000 (13:57 +0000)
* target.def (function_switched_text_sections): New Hook.
* doc/tm.texi Regenerated.
* doc/tm.texi.in (TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS)
New.
* final.c (default_function_switched_text_sections): New.
(final_scan_insn): Call function_switched_text_sections when a mid-function section
change occurs.
* output.h (default_function_switched_text_sections): Declare.
* config/darwin-protos.h (darwin_function_switched_text_sections) : Likewise.
* config/darwin.c (darwin_function_switched_text_sections): New.
* config/darwin.h (TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS)
New.

From-SVN: r168571

gcc/ChangeLog
gcc/config/darwin-protos.h
gcc/config/darwin.c
gcc/config/darwin.h
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/final.c
gcc/output.h
gcc/target.def

index 01438e72d39ce27aba35adf963d623e2d19aa30d..54c14cc9236c8e3be7603583d6f295c7121d0b6f 100644 (file)
@@ -1,3 +1,18 @@
+2011-01-07  Iain Sandoe  <iains@gcc.gnu.org>
+
+       * target.def (function_switched_text_sections): New Hook.
+       * doc/tm.texi Regenerated.
+       * doc/tm.texi.in (TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS)
+       New.
+       * final.c (default_function_switched_text_sections): New.
+       (final_scan_insn): Call function_switched_text_sections when a mid-function section
+       change occurs.
+       * output.h (default_function_switched_text_sections): Declare.
+       * config/darwin-protos.h (darwin_function_switched_text_sections) : Likewise.
+       * config/darwin.c (darwin_function_switched_text_sections): New.
+       * config/darwin.h (TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS)
+       New.
+
 2011-01-07  Iain Sandoe  <iains@gcc.gnu.org>
 
        * dwarf2out.c (gen_subprogram_die):  Add pubnames with code ranges for
index fca8065e074dbb2d0b2f138825a65f31a52082d5..bf81ed97c4c137c77a64c06d8d4dcea61d87c928 100644 (file)
@@ -58,6 +58,8 @@ extern section *machopic_select_rtx_section (enum machine_mode, rtx,
                                             unsigned HOST_WIDE_INT);
 
 extern section *darwin_function_section (tree, enum node_frequency, bool, bool); 
+extern void darwin_function_switched_text_sections (FILE *, tree, bool);
+
 extern void darwin_unique_section (tree decl, int reloc);
 extern void darwin_asm_named_section (const char *, unsigned int, tree);
 extern void darwin_non_lazy_pcrel (FILE *, rtx);
index d9185dbeb762fabe02c0ee0fb9991302f1cedcdb..5560bf913fb3e7df0401bd1b9ee7e3d6e6056f5e 100644 (file)
@@ -2572,18 +2572,6 @@ darwin_override_options (void)
   if (!global_options_set.x_dwarf_strict) 
     dwarf_strict = 1;
 
-  /* FIXME: Darwin cannot support multiple function sections until (a) the new code
-     atoms created have a proper start label and (b) there are suitable pubnames 
-     emitted.  This applies to all current Darwin versions (OSX <= 10.6.5).  */
-  if (global_options.x_flag_reorder_blocks_and_partition)
-    {
-      inform (input_location,
-             "-freorder-blocks-and-partition is currently disabled for this "
-             "platform");
-      flag_reorder_blocks_and_partition = 0;
-      flag_reorder_blocks = 1;
-    }
-
   /* Do not allow unwind tables to be generated by default for m32.  
      fnon-call-exceptions will override this, regardless of what we do.  */
   if (generating_for_darwin_version < 10
@@ -2591,13 +2579,13 @@ darwin_override_options (void)
       && !TARGET_64BIT)
     global_options.x_flag_asynchronous_unwind_tables = 0;
 
-  /* Disable -freorder-blocks-and-partition when unwind tables are being emitted
-     for Darwin < 10 (OSX 10.6).  
-     The strategy is, "Unless the User has specifically set/unset an unwind flag
-     we will switch off -freorder-blocks-and-partition when unwind tables will be
-     generated".  If the User specifically sets flags... we assume (s)he knows
-     why...  */
-   if (generating_for_darwin_version < 10
+   /* Disable -freorder-blocks-and-partition when unwind tables are being emitted
+      for Darwin < 10 (OSX 10.6).  
+      The strategy is, "Unless the User has specifically set/unset an unwind flag
+      we will switch off -freorder-blocks-and-partition when unwind tables will be
+      generated".  If the User specifically sets flags... we assume (s)he knows
+      why...  */
+   if (generating_for_darwin_version < 9
        && global_options_set.x_flag_reorder_blocks_and_partition
        && ((global_options.x_flag_exceptions           /* User, c++, java */
            && !global_options_set.x_flag_exceptions)   /* User specified... */
@@ -2607,13 +2595,6 @@ darwin_override_options (void)
                && !global_options_set.x_flag_non_call_exceptions)
           || (global_options.x_flag_asynchronous_unwind_tables
                && !global_options_set.x_flag_asynchronous_unwind_tables)))
-    {
-      inform (input_location,
-             "-freorder-blocks-and-partition does not work with exceptions "
-             "on this architecture");
-      flag_reorder_blocks_and_partition = 0;
-      flag_reorder_blocks = 1;
-    }
 
   if (flag_mkernel || flag_apple_kext)
     {
@@ -3066,4 +3047,21 @@ darwin_function_section (tree decl, enum node_frequency freq,
     }
 }
 
+/* When a function is partitioned between sections, we need to insert a label
+   at the start of each new chunk - so that it may become a valid 'atom' for
+   eh and debug purposes.  Without this the linker will emit warnings if one 
+   tries to add line location information (since the switched fragment will 
+   be anonymous).  */
+
+void
+darwin_function_switched_text_sections (FILE *fp, tree decl, bool new_is_cold)
+{
+  char buf[128];
+  snprintf (buf, 128, "%s%s",new_is_cold?"__cold_sect_of_":"__hot_sect_of_",
+           IDENTIFIER_POINTER (DECL_NAME (decl)));
+  /* Make sure we pick up all the relevant quotes etc.  */
+  assemble_name_raw (fp, (const char *) buf);
+  fputs (":\n", fp);
+}
+
 #include "gt-darwin.h"
index 9092d6be397239075a04033e7e119c22d9d46c02..74ced9c31ca8bb4c87c8cff25ad18cb648e1eaee 100644 (file)
@@ -673,6 +673,10 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS];
 #undef TARGET_ASM_FUNCTION_SECTION
 #define TARGET_ASM_FUNCTION_SECTION darwin_function_section
 
+#undef TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS
+#define TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS \
+       darwin_function_switched_text_sections
+
 #undef TARGET_ASM_SELECT_RTX_SECTION
 #define TARGET_ASM_SELECT_RTX_SECTION machopic_select_rtx_section
 #undef  TARGET_ASM_UNIQUE_SECTION
index b13ddfb5a59245b8d45dac6da5390c41bc7cc801..139c5a7374cb9cd8703d4b964f63090ed414464c 100644 (file)
@@ -7325,6 +7325,10 @@ at startup (from static constructors or it is @code{main()}).
 Return NULL if function should go to default text section.
 @end deftypefn
 
+@deftypefn {Target Hook} void TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS (FILE *@var{file}, tree @var{decl}, bool @var{new_is_cold})
+Used by the target to emit any assembler directives or additional  labels needed when a function is partitioned between different  sections.  Output should be written to @var{file}.  The function  decl is available as @var{decl} and the new section is `cold' if  @var{new_is_cold} is @code{true}.
+@end deftypefn
+
 @deftypevr {Target Hook} bool TARGET_HAVE_NAMED_SECTIONS
 This flag is true if the target supports @code{TARGET_ASM_NAMED_SECTION}.
 It must not be modified by command-line option processing.
index f78eba957176e2fb1009cdfe7ac210f77f753ae9..208581645bcdd6d97d9aaf7b800ddfd754558899 100644 (file)
@@ -7298,6 +7298,8 @@ at startup (from static constructors or it is @code{main()}).
 Return NULL if function should go to default text section.
 @end deftypefn
 
+@hook TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS
+
 @hook TARGET_HAVE_NAMED_SECTIONS
 This flag is true if the target supports @code{TARGET_ASM_NAMED_SECTION}.
 It must not be modified by command-line option processing.
index ebe21b607652e65e8ca750451be1f2c788f1dbba..09dec08e0eabe4fa30f6152df84d0a98a78c4e42 100644 (file)
@@ -256,6 +256,13 @@ default_function_pro_epilogue (FILE *file ATTRIBUTE_UNUSED,
 {
 }
 
+void
+default_function_switched_text_sections (FILE *file ATTRIBUTE_UNUSED,
+                                        tree decl ATTRIBUTE_UNUSED,
+                                        bool new_is_cold ATTRIBUTE_UNUSED)
+{
+}
+
 /* Default target hook that outputs nothing to a stream.  */
 void
 no_asm_to_stream (FILE *file ATTRIBUTE_UNUSED)
@@ -1841,6 +1848,9 @@ final_scan_insn (rtx insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED,
            debug_hooks->switch_text_section ();
 
          switch_to_section (current_function_section ());
+         targetm.asm_out.function_switched_text_sections (asm_out_file,
+                                                          current_function_decl,
+                                                          in_cold_section_p);
          break;
 
        case NOTE_INSN_BASIC_BLOCK:
index 6a835c0f932b25da13851478c01290cbeacc44c7..39225a3a6cc10730f19060fa043b101143119ccd 100644 (file)
@@ -417,6 +417,9 @@ extern const char *user_label_prefix;
 /* Default target function prologue and epilogue assembler output.  */
 extern void default_function_pro_epilogue (FILE *, HOST_WIDE_INT);
 
+/* Default target function switched text sections.  */
+extern void default_function_switched_text_sections (FILE *, tree, bool);
+
 /* Default target hook that outputs nothing to a stream.  */
 extern void no_asm_to_stream (FILE *);
 
index 653981f71ad7488cc453f99324a97d595a1d732a..9d96e65e537d7f2546127cd1083b4441d3b8ac9f 100644 (file)
@@ -294,6 +294,17 @@ DEFHOOK
  section *, (tree decl, enum node_frequency freq, bool startup, bool exit),
  default_function_section)
 
+/* Output the assembler code for function exit.  */
+DEFHOOK
+(function_switched_text_sections,
+ "Used by the target to emit any assembler directives or additional\
+  labels needed when a function is partitioned between different\
+  sections.  Output should be written to @var{file}.  The function\
+  decl is available as @var{decl} and the new section is `cold' if\
+  @var{new_is_cold} is @code{true}.",
+ void, (FILE *file, tree decl, bool new_is_cold),
+ default_function_switched_text_sections)
+
 /* Return a mask describing how relocations should be treated when
    selecting sections.  Bit 1 should be set if global relocations
    should be placed in a read-write section; bit 0 should be set if