arm.md (tablejump): Make this a define_expand.
authorRichard Earnshaw <rearnsha@arm.com>
Mon, 18 Mar 2002 11:26:24 +0000 (11:26 +0000)
committerRichard Earnshaw <rearnsha@gcc.gnu.org>
Mon, 18 Mar 2002 11:26:24 +0000 (11:26 +0000)
* arm.md (tablejump): Make this a define_expand.  For PIC add the
offset to the base of the table.
(thumb_tablejump): Matcher for Thumb tablejump insn.
* config/arm/aout.h (ASM_OUTPUT_ADDR_DIFF_ELT): Output thumb entries
as the difference of two labels.
* config/arm/aof.h (ASM_OUTPUT_ADDR_DIFF_ELT): Likewise.
* config/arm/elf.h (JUMP_TABLES_IN_TEXT_SECTION): Only put ARM jump
tables in the code.
* config/arm/coff.h (JUMP_TABLES_IN_TEXT_SECTION): Likewise.
* arm.c (get_jump_table_size): If the table is not in the text
section, return zero.

From-SVN: r50960

gcc/ChangeLog
gcc/config/arm/aof.h
gcc/config/arm/aout.h
gcc/config/arm/arm.c
gcc/config/arm/arm.md
gcc/config/arm/coff.h
gcc/config/arm/elf.h

index 4de4c64e4258394773d8ddcd11087c4e8b10e3be..42a48bbeb7bfe359b1acfe2c2cb46549fadb9828 100644 (file)
@@ -1,3 +1,17 @@
+2002-03-18  Richard Earnshaw  <rearnsha@arm.com>
+
+       * arm.md (tablejump): Make this a define_expand.  For PIC add the
+       offset to the base of the table.
+       (thumb_tablejump): Matcher for Thumb tablejump insn.
+       * config/arm/aout.h (ASM_OUTPUT_ADDR_DIFF_ELT): Output thumb entries
+       as the difference of two labels.
+       * config/arm/aof.h (ASM_OUTPUT_ADDR_DIFF_ELT): Likewise.
+       * config/arm/elf.h (JUMP_TABLES_IN_TEXT_SECTION): Only put ARM jump
+       tables in the code.
+       * config/arm/coff.h (JUMP_TABLES_IN_TEXT_SECTION): Likewise.
+       * arm.c (get_jump_table_size): If the table is not in the text
+       section, return zero.
+       
 2002-03-18  Bernd Schmidt  <bernds@redhat.com>
 
        * config/arm/arm.c (arm_gen_movstrqi): Use gen_lowpart instead
index 750bc08d123682df03f843e85e3a28b783d24ae9..f110ea215d13c79993ee3bb307273ecf4251da95 100644 (file)
@@ -120,6 +120,10 @@ do {                                       \
     (*ptr++) ();                       \
 } while (0)
 
+/* We really want to put Thumb tables in a read-only data section, but
+   switching to another section during function output is not
+   possible.  We could however do what the SPARC does and defer the
+   whole table generation until the end of the function.  */
 #define JUMP_TABLES_IN_TEXT_SECTION 1
 
 #ifndef ARM_OS_NAME
@@ -322,8 +326,13 @@ do {                                       \
 
 /* Output of Dispatch Tables */
 
-#define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM,BODY,VALUE,REL)                \
-  fprintf ((STREAM), "\tb\t|L..%d|\n", (VALUE))
+#define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM,BODY,VALUE,REL)                        \
+  do {                                                                 \
+    if (TARGET_ARM)                                                    \
+      fprintf ((STREAM), "\tb\t|L..%d|\n", (VALUE));                   \
+    else                                                               \
+      fprintf ((STREAM), "\tDCD\t|L..%d| - |L..%d|\n", (VALUE), (REL));        \
+  } while (0)
 
 #define ASM_OUTPUT_ADDR_VEC_ELT(STREAM,VALUE)  \
   fprintf ((STREAM), "\tDCD\t|L..%d|\n", (VALUE))
index 64ca8b7caac1eab6ca31b6929abbd733c11c275a..868eee0c7c8657c45d0442e4d06ce5490989d1c0 100644 (file)
@@ -181,8 +181,16 @@ Boston, MA 02111-1307, USA.  */
 #define ASM_OUTPUT_ADDR_VEC_ELT(STREAM, VALUE)  \
   asm_fprintf (STREAM, "\t.word\t%LL%d\n", VALUE)
 
-#define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM, BODY, VALUE, REL)  \
-  asm_fprintf (STREAM, "\tb\t%LL%d\n", VALUE)
+#define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM, BODY, VALUE, REL)             \
+  do                                                                   \
+    {                                                                  \
+      if (TARGET_ARM)                                                  \
+       asm_fprintf (STREAM, "\tb\t%LL%d\n", VALUE);                    \
+      else                                                             \
+       asm_fprintf (STREAM, "\t.word\t%LL%d-%LL%d\n", VALUE, REL);     \
+    }                                                                  \
+  while (0)
+
 
 #undef  ASM_OUTPUT_ASCII
 #define ASM_OUTPUT_ASCII(STREAM, PTR, LEN)  \
index 4b1775810b1069de485bbcba78118ce9b21645fc..8ed4c6db131e4ec8401f401f08a38b7920c36381 100644 (file)
@@ -5329,14 +5329,29 @@ is_jump_table (insn)
   return NULL_RTX;
 }
 
+#ifndef JUMP_TABLES_IN_TEXT_SECTION
+#define JUMP_TABLES_IN_TEXT_SECTION 0
+#endif
+
 static HOST_WIDE_INT
 get_jump_table_size (insn)
      rtx insn;
 {
-  rtx body = PATTERN (insn);
-  int elt = GET_CODE (body) == ADDR_DIFF_VEC ? 1 : 0;
+  /* ADDR_VECs only take room if read-only data does into the text
+     section.  */
+  if (JUMP_TABLES_IN_TEXT_SECTION
+#if !defined(READONLY_DATA_SECTION)
+      || 1
+#endif
+      )
+    {
+      rtx body = PATTERN (insn);
+      int elt = GET_CODE (body) == ADDR_DIFF_VEC ? 1 : 0;
+
+      return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, elt);
+    }
 
-  return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, elt);
+  return 0;
 }
 
 /* Move a minipool fix MP from its current location to before MAX_MP.
index af0c9ecf1cfb1f23283735282a65843d628c96cb..cdab5c66ff80743c214928c36ca56fcb25f3f476 100644 (file)
 
 ;; Miscellaneous Thumb patterns
 
-(define_insn "tablejump"
+(define_expand "tablejump"
+  [(parallel [(set (pc) (match_operand:SI 0 "register_operand" "l*r"))
+             (use (label_ref (match_operand 1 "" "")))])]
+  "TARGET_THUMB"
+  "
+  if (flag_pic)
+    {
+      /* Hopefully, CSE will eliminate this copy.  */
+      rtx reg1 = copy_addr_to_reg (gen_rtx_LABEL_REF (Pmode, operands[1]));
+      rtx reg2 = gen_reg_rtx (SImode);
+
+      emit_insn (gen_addsi3 (reg2, operands[0], reg1));
+      operands[0] = reg2;
+    }
+  "
+)
+
+(define_insn "*thumb_tablejump"
   [(set (pc) (match_operand:SI 0 "register_operand" "l*r"))
    (use (label_ref (match_operand 1 "" "")))]
   "TARGET_THUMB"
-  "mov pc, %0"
+  "mov\\t%|pc, %0"
   [(set_attr "length" "2")]
 )
 
index f53dace9056d9b25f05c9c6dc96c3ae392b7af5c..c9f0d9277ab2bed33e13e1bc7775cfb456990b70 100644 (file)
@@ -72,7 +72,9 @@ Boston, MA 02111-1307, USA.  */
 /* Define this macro if jump tables (for `tablejump' insns) should be
    output in the text section, along with the assembler instructions.
    Otherwise, the readonly data section is used.  */
-#define JUMP_TABLES_IN_TEXT_SECTION 1
+/* We put ARM jump tables in the text section, because it makes the code
+   more efficient, but for Thumb it's better to put them out of band.  */
+#define JUMP_TABLES_IN_TEXT_SECTION (TARGET_ARM)
 
 #undef  READONLY_DATA_SECTION
 #define READONLY_DATA_SECTION  rdata_section
index c27dacaa58bf6bffe02a11f021fb1e4c56570406..1cab2c4e144fb2cf3ac4b5155484b150dfba49cb 100644 (file)
@@ -103,7 +103,9 @@ Boston, MA 02111-1307, USA.  */
 /* Define this macro if jump tables (for `tablejump' insns) should be
    output in the text section, along with the assembler instructions.
    Otherwise, the readonly data section is used.  */
-#define JUMP_TABLES_IN_TEXT_SECTION 1
+/* We put ARM jump tables in the text section, because it makes the code
+   more efficient, but for Thumb it's better to put them out of band.  */
+#define JUMP_TABLES_IN_TEXT_SECTION (TARGET_ARM)
 
 #ifndef LINK_SPEC
 #define LINK_SPEC "%{mbig-endian:-EB} -X"