Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-11-26 Thread HAO CHEN GUI via Gcc-patches

Segher,

  Thanks for your comments. I have modified the patch according to your 
advice and committed.


On 24/11/2020 上午 6:25, Segher Boessenkool wrote:

Hi!

Sorry this took so long.

On Thu, Oct 15, 2020 at 04:46:01PM +0800, HAO CHEN GUI wrote:

On 29/9/2020 上午 6:46, Segher Boessenkool wrote:

[ Please do not insert patches into discussions ]

So, please send new patches as a new thread.  This makes it much easier
to handle.  If you want to reply to something in the old thread just do
it there, but send the new patch not as a reply.


* config/rs6000/rs6000.opt (mrelative-jumptables): Add
mrelative-jumptables.

Just "New." or "New flag." or similar?


+/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC.
+   Marco relative jumpstables indicates addr_diff_vec or addr_vec.  */

The documentation says
   Return true to generate ADDR_DIF_VEC table or false to generate
   ADDR_VEC table for jumps in case of -fPIC.
but you can just leave out that last line completely.


+  if (rs6000_relative_jumptables)
+   {
+ if (TARGET_32BIT)
+   jump = gen_tablejumpsi_nospec (operands[0], operands[1], ccreg);
+ else
+   jump = gen_tablejumpdi_nospec (operands[0], operands[1], ccreg);
+   }
else
-   jump = gen_tablejumpdi_nospec (operands[0], operands[1], ccreg);
+   jump = gen_tablejump_absolute_nospec (Pmode, operands[0], operands[1],
+ ccreg);
emit_jump_insn (jump);

It now is
   @tablejump_nospec
so this code will become something like

   if (rs6000_relative_jumptables)
jump = gen_tablejumpsi_nospec (Pmode, operands[0], operands[1], ccreg);
   else
jump = gen_tablejump_absolute_nospec (Pmode, operands[0], operands[1],
  ccreg);
   emit_jump_insn (jump);


Okay for trunk with those changes.  Thank you!


Segher


Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-11-23 Thread Segher Boessenkool
Hi!

Sorry this took so long.

On Thu, Oct 15, 2020 at 04:46:01PM +0800, HAO CHEN GUI wrote:
> On 29/9/2020 上午 6:46, Segher Boessenkool wrote:
> >[ Please do not insert patches into discussions ]

So, please send new patches as a new thread.  This makes it much easier
to handle.  If you want to reply to something in the old thread just do
it there, but send the new patch not as a reply.

>   * config/rs6000/rs6000.opt (mrelative-jumptables): Add
>   mrelative-jumptables.

Just "New." or "New flag." or similar?

> +/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC.
> +   Marco relative jumpstables indicates addr_diff_vec or addr_vec.  */

The documentation says
  Return true to generate ADDR_DIF_VEC table or false to generate
  ADDR_VEC table for jumps in case of -fPIC.
but you can just leave out that last line completely.

> +  if (rs6000_relative_jumptables)
> + {
> +   if (TARGET_32BIT)
> + jump = gen_tablejumpsi_nospec (operands[0], operands[1], ccreg);
> +   else
> + jump = gen_tablejumpdi_nospec (operands[0], operands[1], ccreg);
> + }
>else
> - jump = gen_tablejumpdi_nospec (operands[0], operands[1], ccreg);
> + jump = gen_tablejump_absolute_nospec (Pmode, operands[0], operands[1],
> +   ccreg);
>emit_jump_insn (jump);

It now is
  @tablejump_nospec
so this code will become something like

  if (rs6000_relative_jumptables)
jump = gen_tablejumpsi_nospec (Pmode, operands[0], operands[1], ccreg);
  else
jump = gen_tablejump_absolute_nospec (Pmode, operands[0], operands[1],
  ccreg);
  emit_jump_insn (jump);


Okay for trunk with those changes.  Thank you!


Segher


Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-11-22 Thread HAO CHEN GUI via Gcc-patches

Hi,

Gentle ping this:

https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556236.html

Thanks.

Gui Haochen

On 6/11/2020 上午 9:02, HAO CHEN GUI wrote:

Hi,

Gentle ping this:

https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556236.html

Thanks.

Gui Haochen


On 15/10/2020 下午 4:46, HAO CHEN GUI wrote:

Segher,

    I re-wrote the patch based on parameterized name.

    The attachments are the patch diff file and change log file.

    Bootstrapped and tested on powerpc64le-linux-gnu with no 
regressions.  Is this okay for trunk? Any recommendations? Thanks a lot.



On 29/9/2020 上午 6:46, Segher Boessenkool wrote:

Hi hao Chen,

On Wed, Sep 09, 2020 at 04:55:29PM +0800, HAO CHEN GUI wrote:

 Thanks for your advice. I removed macros defined in linux64.h and
linux.h. So they take relative jump tables by default. When
no-relative-jumptables is set, the absolute jump tables are taken. All
things relevant to section relocations are put in another patch. 
Thanks

again.

[ Please do not insert patches into discussions ]


+/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC.
+   Return true if rs6000_relative_jumptables is set.  */

Don't just say what the code does (we can see that ;-) ); say *why*.
Of course it is terribly simple in this case, so maybe just that first
line is plenty.


+/* Specify the machine mode that this machine uses
+   for the index in the tablejump instruction.  */
+#define CASE_VECTOR_MODE \
+  (TARGET_32BIT || rs6000_relative_jumptables ? SImode : Pmode)

If TARGET_32BIT is true, SImode and Pmode are the same, so this is
simpler said as

#define CASE_VECTOR_MODE (rs6000_relative_jumptables ? SImode : Pmode)


I'll have the tablejump* patterns converted to paremeterized names
hopefully tonight or tomorrow, which will make your patch much easier
to read.  It looks like it will be fine, thanks :-)


Segher


Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-11-15 Thread HAO CHEN GUI via Gcc-patches

Hi,

Gentle ping this:

https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556236.html

Thanks.

Gui Haochen

On 6/11/2020 上午 9:02, HAO CHEN GUI wrote:

Hi,

Gentle ping this:

https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556236.html

Thanks.

Gui Haochen


On 15/10/2020 下午 4:46, HAO CHEN GUI wrote:

Segher,

    I re-wrote the patch based on parameterized name.

    The attachments are the patch diff file and change log file.

    Bootstrapped and tested on powerpc64le-linux-gnu with no 
regressions.  Is this okay for trunk? Any recommendations? Thanks a lot.



On 29/9/2020 上午 6:46, Segher Boessenkool wrote:

Hi hao Chen,

On Wed, Sep 09, 2020 at 04:55:29PM +0800, HAO CHEN GUI wrote:

 Thanks for your advice. I removed macros defined in linux64.h and
linux.h. So they take relative jump tables by default. When
no-relative-jumptables is set, the absolute jump tables are taken. All
things relevant to section relocations are put in another patch. 
Thanks

again.

[ Please do not insert patches into discussions ]


+/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC.
+   Return true if rs6000_relative_jumptables is set.  */

Don't just say what the code does (we can see that ;-) ); say *why*.
Of course it is terribly simple in this case, so maybe just that first
line is plenty.


+/* Specify the machine mode that this machine uses
+   for the index in the tablejump instruction.  */
+#define CASE_VECTOR_MODE \
+  (TARGET_32BIT || rs6000_relative_jumptables ? SImode : Pmode)

If TARGET_32BIT is true, SImode and Pmode are the same, so this is
simpler said as

#define CASE_VECTOR_MODE (rs6000_relative_jumptables ? SImode : Pmode)


I'll have the tablejump* patterns converted to paremeterized names
hopefully tonight or tomorrow, which will make your patch much easier
to read.  It looks like it will be fine, thanks :-)


Segher
* config/rs6000/rs6000-protos.h (rs6000_output_addr_vec_elt): Declare.
* config/rs6000/rs6000.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC):
Define.
(rs6000_gen_pic_addr_diff_vec, rs6000_output_addr_vec_elt): Implement.
* config/rs6000/rs6000.h (CASE_VECTOR_PC_RELATIVE,
CASE_VECTOR_MODE, ASM_OUTPUT_ADDR_VEC_ELT): Define.
* config/rs6000/rs6000.md (tablejump_absolute,
tablejump_absolute_nospec): New expanders.
* config/rs6000/rs6000.opt (mrelative-jumptables): Add
mrelative-jumptables.
diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index 25fa5dd57cd..49ab51042c5 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -155,6 +155,7 @@ extern void rs6000_split_logical (rtx [], enum rtx_code, 
bool, bool, bool);
 extern bool rs6000_function_pcrel_p (struct function *);
 extern bool rs6000_pcrel_p (void);
 extern bool rs6000_fndecl_pcrel_p (const_tree);
+extern void rs6000_output_addr_vec_elt (FILE *, int);
 
 /* Different PowerPC instruction formats that are used by GCC.  There are
various other instruction formats used by the PowerPC hardware, but these
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index b58eeae2b98..7e441f7e730 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -1367,6 +1367,9 @@ static const struct attribute_spec 
rs6000_attribute_table[] =
 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA rs6000_output_addr_const_extra
 
+#undef  TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC
+#define TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC rs6000_gen_pic_addr_diff_vec
+
 #undef TARGET_LEGITIMIZE_ADDRESS
 #define TARGET_LEGITIMIZE_ADDRESS rs6000_legitimize_address
 
@@ -27053,6 +27056,27 @@ rs6000_emit_xxspltidp_v2df (rtx dst, long value)
   emit_insn( gen_xxspltidp_v2df_inst (dst, GEN_INT (value)));
 }
 
+/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC.
+   Marco relative jumpstables indicates addr_diff_vec or addr_vec.  */
+
+static bool
+rs6000_gen_pic_addr_diff_vec (void)
+{
+  return rs6000_relative_jumptables;
+}
+
+void
+rs6000_output_addr_vec_elt (FILE *file, int value)
+{
+  const char *directive = TARGET_64BIT ? DOUBLE_INT_ASM_OP : "\t.long\t";
+  char buf[100];
+
+  fprintf (file, "%s", directive);
+  ASM_GENERATE_INTERNAL_LABEL (buf, "L", value);
+  assemble_name (file, buf);
+  fprintf (file, "\n");
+}
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-rs6000.h"
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index bbd8060e143..4a948e25f71 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -1754,15 +1754,15 @@ typedef struct rs6000_args
 
 /* #define LEGITIMATE_PIC_OPERAND_P (X) */
 
-/* Specify the machine mode that this machine uses
-   for the index in the tablejump instruction.  */
-#define CASE_VECTOR_MODE SImode
-
 /* Define as C expression which evaluates to nonzero if the tablejump
instruction expects the table to contain offsets from the address of the

Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-11-05 Thread HAO CHEN GUI via Gcc-patches

Hi,

Gentle ping this:

https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556236.html

Thanks.

Gui Haochen


On 15/10/2020 下午 4:46, HAO CHEN GUI wrote:

Segher,

    I re-wrote the patch based on parameterized name.

    The attachments are the patch diff file and change log file.

    Bootstrapped and tested on powerpc64le-linux-gnu with no 
regressions.  Is this okay for trunk? Any recommendations? Thanks a lot.



On 29/9/2020 上午 6:46, Segher Boessenkool wrote:

Hi hao Chen,

On Wed, Sep 09, 2020 at 04:55:29PM +0800, HAO CHEN GUI wrote:

 Thanks for your advice. I removed macros defined in linux64.h and
linux.h. So they take relative jump tables by default. When
no-relative-jumptables is set, the absolute jump tables are taken. All
things relevant to section relocations are put in another patch. Thanks
again.

[ Please do not insert patches into discussions ]


+/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC.
+   Return true if rs6000_relative_jumptables is set.  */

Don't just say what the code does (we can see that ;-) ); say *why*.
Of course it is terribly simple in this case, so maybe just that first
line is plenty.


+/* Specify the machine mode that this machine uses
+   for the index in the tablejump instruction.  */
+#define CASE_VECTOR_MODE \
+  (TARGET_32BIT || rs6000_relative_jumptables ? SImode : Pmode)

If TARGET_32BIT is true, SImode and Pmode are the same, so this is
simpler said as

#define CASE_VECTOR_MODE (rs6000_relative_jumptables ? SImode : Pmode)


I'll have the tablejump* patterns converted to paremeterized names
hopefully tonight or tomorrow, which will make your patch much easier
to read.  It looks like it will be fine, thanks :-)


Segher


Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-10-15 Thread HAO CHEN GUI via Gcc-patches

Segher,

    I re-wrote the patch based on parameterized name.

    The attachments are the patch diff file and change log file.

    Bootstrapped and tested on powerpc64le-linux-gnu with no 
regressions.  Is this okay for trunk? Any recommendations? Thanks a lot.



On 29/9/2020 上午 6:46, Segher Boessenkool wrote:

Hi hao Chen,

On Wed, Sep 09, 2020 at 04:55:29PM +0800, HAO CHEN GUI wrote:

     Thanks for your advice. I removed macros defined in linux64.h and
linux.h. So they take relative jump tables by default. When
no-relative-jumptables is set, the absolute jump tables are taken. All
things relevant to section relocations are put in another patch. Thanks
again.

[ Please do not insert patches into discussions ]


+/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC.
+   Return true if rs6000_relative_jumptables is set.  */

Don't just say what the code does (we can see that ;-) ); say *why*.
Of course it is terribly simple in this case, so maybe just that first
line is plenty.


+/* Specify the machine mode that this machine uses
+   for the index in the tablejump instruction.  */
+#define CASE_VECTOR_MODE \
+  (TARGET_32BIT || rs6000_relative_jumptables ? SImode : Pmode)

If TARGET_32BIT is true, SImode and Pmode are the same, so this is
simpler said as

#define CASE_VECTOR_MODE (rs6000_relative_jumptables ? SImode : Pmode)


I'll have the tablejump* patterns converted to paremeterized names
hopefully tonight or tomorrow, which will make your patch much easier
to read.  It looks like it will be fine, thanks :-)


Segher
* config/rs6000/rs6000-protos.h (rs6000_output_addr_vec_elt): Declare.
* config/rs6000/rs6000.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC):
Define.
(rs6000_gen_pic_addr_diff_vec, rs6000_output_addr_vec_elt): Implement.
* config/rs6000/rs6000.h (CASE_VECTOR_PC_RELATIVE,
CASE_VECTOR_MODE, ASM_OUTPUT_ADDR_VEC_ELT): Define.
* config/rs6000/rs6000.md (tablejump_absolute,
tablejump_absolute_nospec): New expanders.
* config/rs6000/rs6000.opt (mrelative-jumptables): Add
mrelative-jumptables.
diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index 25fa5dd57cd..49ab51042c5 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -155,6 +155,7 @@ extern void rs6000_split_logical (rtx [], enum rtx_code, 
bool, bool, bool);
 extern bool rs6000_function_pcrel_p (struct function *);
 extern bool rs6000_pcrel_p (void);
 extern bool rs6000_fndecl_pcrel_p (const_tree);
+extern void rs6000_output_addr_vec_elt (FILE *, int);
 
 /* Different PowerPC instruction formats that are used by GCC.  There are
various other instruction formats used by the PowerPC hardware, but these
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index b58eeae2b98..7e441f7e730 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -1367,6 +1367,9 @@ static const struct attribute_spec 
rs6000_attribute_table[] =
 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA rs6000_output_addr_const_extra
 
+#undef  TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC
+#define TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC rs6000_gen_pic_addr_diff_vec
+
 #undef TARGET_LEGITIMIZE_ADDRESS
 #define TARGET_LEGITIMIZE_ADDRESS rs6000_legitimize_address
 
@@ -27053,6 +27056,27 @@ rs6000_emit_xxspltidp_v2df (rtx dst, long value)
   emit_insn( gen_xxspltidp_v2df_inst (dst, GEN_INT (value)));
 }
 
+/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC.
+   Marco relative jumpstables indicates addr_diff_vec or addr_vec.  */
+
+static bool
+rs6000_gen_pic_addr_diff_vec (void)
+{
+  return rs6000_relative_jumptables;
+}
+
+void
+rs6000_output_addr_vec_elt (FILE *file, int value)
+{
+  const char *directive = TARGET_64BIT ? DOUBLE_INT_ASM_OP : "\t.long\t";
+  char buf[100];
+
+  fprintf (file, "%s", directive);
+  ASM_GENERATE_INTERNAL_LABEL (buf, "L", value);
+  assemble_name (file, buf);
+  fprintf (file, "\n");
+}
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-rs6000.h"
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index bbd8060e143..4a948e25f71 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -1754,15 +1754,15 @@ typedef struct rs6000_args
 
 /* #define LEGITIMATE_PIC_OPERAND_P (X) */
 
-/* Specify the machine mode that this machine uses
-   for the index in the tablejump instruction.  */
-#define CASE_VECTOR_MODE SImode
-
 /* Define as C expression which evaluates to nonzero if the tablejump
instruction expects the table to contain offsets from the address of the
table.
Do not define this if the table should contain absolute addresses.  */
-#define CASE_VECTOR_PC_RELATIVE 1
+#define CASE_VECTOR_PC_RELATIVE rs6000_relative_jumptables
+
+/* Specify the machine mode that this machine uses
+   for the index in the tablejump instruction.  */
+#define CASE_VECTOR_MODE 

Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-09-28 Thread Segher Boessenkool
Hi hao Chen,

On Wed, Sep 09, 2020 at 04:55:29PM +0800, HAO CHEN GUI wrote:
>     Thanks for your advice. I removed macros defined in linux64.h and 
> linux.h. So they take relative jump tables by default. When 
> no-relative-jumptables is set, the absolute jump tables are taken. All 
> things relevant to section relocations are put in another patch. Thanks 
> again.

[ Please do not insert patches into discussions ]

> +/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC.
> +   Return true if rs6000_relative_jumptables is set.  */

Don't just say what the code does (we can see that ;-) ); say *why*.
Of course it is terribly simple in this case, so maybe just that first
line is plenty.

> +/* Specify the machine mode that this machine uses
> +   for the index in the tablejump instruction.  */
> +#define CASE_VECTOR_MODE \
> +  (TARGET_32BIT || rs6000_relative_jumptables ? SImode : Pmode)

If TARGET_32BIT is true, SImode and Pmode are the same, so this is
simpler said as

#define CASE_VECTOR_MODE (rs6000_relative_jumptables ? SImode : Pmode)


I'll have the tablejump* patterns converted to paremeterized names
hopefully tonight or tomorrow, which will make your patch much easier
to read.  It looks like it will be fine, thanks :-)


Segher


Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-09-27 Thread HAO CHEN GUI via Gcc-patches

Segher,

    Gentle ping this:

https://gcc.gnu.org/pipermail/gcc-patches/2020-September/553486.html
Thanks
Gui Haochen

On 9/9/2020 下午 4:55, HAO CHEN GUI wrote:

Hi Segher,

    Thanks for your advice. I removed macros defined in linux64.h and 
linux.h. So they take relative jump tables by default. When 
no-relative-jumptables is set, the absolute jump tables are taken. All 
things relevant to section relocations are put in another patch. 
Thanks again.



On 8/9/2020 上午 5:46, Segher Boessenkool wrote:

On Mon, Aug 24, 2020 at 03:48:43PM +0800, HAO CHEN GUI wrote:
I'll try to be quicker at reviewing iterations of this -- there is 
quite

some way to go, without me slowing things down!

Sigh :-(


* config/rs6000/linux.h (rs6000_relative_jumptables): Define.

That macro looks like it is variable (or function).  *Make* it a
variable, please?


* config/rs6000/rs6000.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC):
Define

Period?

(rs6000_gen_pic_addr_diff_vec, rs6000_output_addr_vec_elt): 
Implement.

"New function."


* config/rs6000/rs6000.md (absolute_tablejumpsi,
absolute_tablejumpsi_nospec, absolute_tablejumpdi,
absolute_tablejumpdi_nospec): Add four new expansions.

"New define_expands." or "New expanders."

* config/rs6000/rs6000.opt (mrelative-jumptables): Add a new 
option and

set rs6000_relative_jumptables to true by default.

"rs6000.opt: Add -mrelative-jumptables."


+/* Disable relative jump tables for Power Linux.  */
+#undef rs6000_relative_jumptables
+#define rs6000_relative_jumptables 0

Why?


+/* Disable relative jump tables for Power Linux64.  */
+#undef rs6000_relative_jumptables
+#define rs6000_relative_jumptables 0

(That's not what it's called...  Just don't say the "for..." at all?
It is clear from what file it is in.)


  /* Indicate that jump tables go in the text section.  */
  #undef  JUMP_TABLES_IN_TEXT_SECTION
-#define JUMP_TABLES_IN_TEXT_SECTION TARGET_64BIT
+#define JUMP_TABLES_IN_TEXT_SECTION rs6000_relative_jumptables

Not sure that is correct.  Maybe the patch using rodata (.data.rel.ro)
should be a separate patch?


  /* Define as C expression which evaluates to nonzero if the tablejump
 instruction expects the table to contain offsets from the 
address of the

 table.
 Do not define this if the table should contain absolute 
addresses.  */

-#define CASE_VECTOR_PC_RELATIVE 1
+#define CASE_VECTOR_PC_RELATIVE 0

This should depend on the new flag?


+/* Specify the machine mode that this machine uses
+   for the index in the tablejump instruction.  */
+#define CASE_VECTOR_MODE \
+  (TARGET_32BIT || rs6000_relative_jumptables ? SImode : DImode)

rs6000_relative_jumptables ? SImode : Pmode;


+  if (rs6000_relative_jumptables)
+    {
+  if (TARGET_32BIT)
+    emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
+  else
+    emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
+    }

Hrm, I guess we should make that a parameterized name (future work,
don't do it now :-) )


+(define_expand "absolute_tablejumpsi"

Don't prefix names; it should start with "tablejump".


Segher
* config/rs6000/rs6000-protos.h (rs6000_output_addr_vec_elt): Declare.
* config/rs6000/rs6000.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC):
Define.
(rs6000_gen_pic_addr_diff_vec, rs6000_output_addr_vec_elt): Implement.
* config/rs6000/rs6000.h (CASE_VECTOR_PC_RELATIVE,
CASE_VECTOR_MODE, ASM_OUTPUT_ADDR_VEC_ELT): Define.
* config/rs6000/rs6000.md (tablejumpsi_absolute,
tablejumpsi_nospec_absolute, tablejumpdi_absolute,
tablejumpdi_nospec_absolute): New expanders.
* config/rs6000/rs6000.opt (mrelative-jumptables): Add
mrelative-jumptables.
diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index 5508484ba19..62564dd67f2 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -155,6 +155,8 @@ extern void rs6000_split_logical (rtx [], enum rtx_code, 
bool, bool, bool);
 extern bool rs6000_pcrel_p (struct function *);
 extern bool rs6000_fndecl_pcrel_p (const_tree);
 
+extern void rs6000_output_addr_vec_elt (FILE *, int);
+
 /* Different PowerPC instruction formats that are used by GCC.  There are
various other instruction formats used by the PowerPC hardware, but these
formats are not currently used by GCC.  */
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 58f5d780603..94d1e650b94 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -1369,6 +1369,9 @@ static const struct attribute_spec 
rs6000_attribute_table[] =
 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA rs6000_output_addr_const_extra
 
+#undef  TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC
+#define TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC rs6000_gen_pic_addr_diff_vec
+
 #undef TARGET_LEGITIMIZE_ADDRESS
 #define 

Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-09-09 Thread HAO CHEN GUI via Gcc-patches

Hi Segher,

    Thanks for your advice. I removed macros defined in linux64.h and 
linux.h. So they take relative jump tables by default. When 
no-relative-jumptables is set, the absolute jump tables are taken. All 
things relevant to section relocations are put in another patch. Thanks 
again.



On 8/9/2020 上午 5:46, Segher Boessenkool wrote:

On Mon, Aug 24, 2020 at 03:48:43PM +0800, HAO CHEN GUI wrote:

I'll try to be quicker at reviewing iterations of this -- there is quite
some way to go, without me slowing things down!

Sigh :-(


* config/rs6000/linux.h (rs6000_relative_jumptables): Define.

That macro looks like it is variable (or function).  *Make* it a
variable, please?


* config/rs6000/rs6000.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC):
Define

Period?


(rs6000_gen_pic_addr_diff_vec, rs6000_output_addr_vec_elt): Implement.

"New function."


* config/rs6000/rs6000.md (absolute_tablejumpsi,
absolute_tablejumpsi_nospec, absolute_tablejumpdi,
absolute_tablejumpdi_nospec): Add four new expansions.

"New define_expands." or "New expanders."


* config/rs6000/rs6000.opt (mrelative-jumptables): Add a new option and
set rs6000_relative_jumptables to true by default.

"rs6000.opt: Add -mrelative-jumptables."


+/* Disable relative jump tables for Power Linux.  */
+#undef rs6000_relative_jumptables
+#define rs6000_relative_jumptables 0

Why?


+/* Disable relative jump tables for Power Linux64.  */
+#undef rs6000_relative_jumptables
+#define rs6000_relative_jumptables 0

(That's not what it's called...  Just don't say the "for..." at all?
It is clear from what file it is in.)


  /* Indicate that jump tables go in the text section.  */
  #undef  JUMP_TABLES_IN_TEXT_SECTION
-#define JUMP_TABLES_IN_TEXT_SECTION TARGET_64BIT
+#define JUMP_TABLES_IN_TEXT_SECTION rs6000_relative_jumptables

Not sure that is correct.  Maybe the patch using rodata (.data.rel.ro)
should be a separate patch?


  /* Define as C expression which evaluates to nonzero if the tablejump
 instruction expects the table to contain offsets from the address of the
 table.
 Do not define this if the table should contain absolute addresses.  */
-#define CASE_VECTOR_PC_RELATIVE 1
+#define CASE_VECTOR_PC_RELATIVE 0

This should depend on the new flag?


+/* Specify the machine mode that this machine uses
+   for the index in the tablejump instruction.  */
+#define CASE_VECTOR_MODE \
+  (TARGET_32BIT || rs6000_relative_jumptables ? SImode : DImode)

rs6000_relative_jumptables ? SImode : Pmode;


+  if (rs6000_relative_jumptables)
+   {
+ if (TARGET_32BIT)
+   emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
+ else
+   emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
+   }

Hrm, I guess we should make that a parameterized name (future work,
don't do it now :-) )


+(define_expand "absolute_tablejumpsi"

Don't prefix names; it should start with "tablejump".


Segher
* config/rs6000/rs6000-protos.h (rs6000_output_addr_vec_elt): Declare.
* config/rs6000/rs6000.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC):
Define.
(rs6000_gen_pic_addr_diff_vec, rs6000_output_addr_vec_elt): Implement.
* config/rs6000/rs6000.h (CASE_VECTOR_PC_RELATIVE,
CASE_VECTOR_MODE, ASM_OUTPUT_ADDR_VEC_ELT): Define.
* config/rs6000/rs6000.md (tablejumpsi_absolute,
tablejumpsi_nospec_absolute, tablejumpdi_absolute,
tablejumpdi_nospec_absolute): New expanders.
* config/rs6000/rs6000.opt (mrelative-jumptables): Add
mrelative-jumptables.
diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index 5508484ba19..62564dd67f2 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -155,6 +155,8 @@ extern void rs6000_split_logical (rtx [], enum rtx_code, 
bool, bool, bool);
 extern bool rs6000_pcrel_p (struct function *);
 extern bool rs6000_fndecl_pcrel_p (const_tree);
 
+extern void rs6000_output_addr_vec_elt (FILE *, int);
+
 /* Different PowerPC instruction formats that are used by GCC.  There are
various other instruction formats used by the PowerPC hardware, but these
formats are not currently used by GCC.  */
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 58f5d780603..94d1e650b94 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -1369,6 +1369,9 @@ static const struct attribute_spec 
rs6000_attribute_table[] =
 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA rs6000_output_addr_const_extra
 
+#undef  TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC
+#define TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC rs6000_gen_pic_addr_diff_vec
+
 #undef TARGET_LEGITIMIZE_ADDRESS
 #define TARGET_LEGITIMIZE_ADDRESS rs6000_legitimize_address
 
@@ -26494,6 +26497,27 @@ rs6000_cannot_substitute_mem_equiv_p (rtx mem)
   return 

Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-09-07 Thread Segher Boessenkool
On Mon, Aug 24, 2020 at 03:48:43PM +0800, HAO CHEN GUI wrote:
> >I'll try to be quicker at reviewing iterations of this -- there is quite
> >some way to go, without me slowing things down!

Sigh :-(

>   * config/rs6000/linux.h (rs6000_relative_jumptables): Define.

That macro looks like it is variable (or function).  *Make* it a
variable, please?

>   * config/rs6000/rs6000.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC):
>   Define

Period?

>   (rs6000_gen_pic_addr_diff_vec, rs6000_output_addr_vec_elt): Implement.

"New function."

>   * config/rs6000/rs6000.md (absolute_tablejumpsi,
>   absolute_tablejumpsi_nospec, absolute_tablejumpdi,
>   absolute_tablejumpdi_nospec): Add four new expansions.

"New define_expands." or "New expanders."

>   * config/rs6000/rs6000.opt (mrelative-jumptables): Add a new option and
>   set rs6000_relative_jumptables to true by default.

"rs6000.opt: Add -mrelative-jumptables."

> +/* Disable relative jump tables for Power Linux.  */
> +#undef rs6000_relative_jumptables
> +#define rs6000_relative_jumptables 0

Why?

> +/* Disable relative jump tables for Power Linux64.  */
> +#undef rs6000_relative_jumptables
> +#define rs6000_relative_jumptables 0

(That's not what it's called...  Just don't say the "for..." at all?
It is clear from what file it is in.)

>  /* Indicate that jump tables go in the text section.  */
>  #undef  JUMP_TABLES_IN_TEXT_SECTION
> -#define JUMP_TABLES_IN_TEXT_SECTION TARGET_64BIT
> +#define JUMP_TABLES_IN_TEXT_SECTION rs6000_relative_jumptables

Not sure that is correct.  Maybe the patch using rodata (.data.rel.ro)
should be a separate patch?

>  /* Define as C expression which evaluates to nonzero if the tablejump
> instruction expects the table to contain offsets from the address of the
> table.
> Do not define this if the table should contain absolute addresses.  */
> -#define CASE_VECTOR_PC_RELATIVE 1
> +#define CASE_VECTOR_PC_RELATIVE 0

This should depend on the new flag?

> +/* Specify the machine mode that this machine uses
> +   for the index in the tablejump instruction.  */
> +#define CASE_VECTOR_MODE \
> +  (TARGET_32BIT || rs6000_relative_jumptables ? SImode : DImode)

rs6000_relative_jumptables ? SImode : Pmode;

> +  if (rs6000_relative_jumptables)
> + {
> +   if (TARGET_32BIT)
> + emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
> +   else
> + emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
> + }

Hrm, I guess we should make that a parameterized name (future work,
don't do it now :-) )

> +(define_expand "absolute_tablejumpsi"

Don't prefix names; it should start with "tablejump".


Segher


Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-08-24 Thread HAO CHEN GUI via Gcc-patches

Hi,

I revised the patch according to the advice. The attachment is the 
change log and diff file. Thanks a lot.


On 20/8/2020 上午 8:14, Segher Boessenkool wrote:

Hi!

Sorry this took so long to review.  "I lost track of this patch", what
can I say :-/

On Fri, Aug 14, 2020 at 03:31:05PM +0800, HAO CHEN GUI wrote:

This patch adds non-relative jump table support on Power Linux. It
implements ASM_OUTPUT_ADDR_VEC_ELT and adds four new expansions for
non-relative jump table in rs6000.md. It also defines a rs6000
option(mrelative-jumptables). If it's set to false, the non-relative
jump table is picked up even PIC flag is set.
diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
index 34776c8421e..626f2201d96 100644
--- a/gcc/config/rs6000/linux64.h
+++ b/gcc/config/rs6000/linux64.h
@@ -324,7 +324,10 @@ extern int dot_symbols;
  
  /* Indicate that jump tables go in the text section.  */

  #undef  JUMP_TABLES_IN_TEXT_SECTION
-#define JUMP_TABLES_IN_TEXT_SECTION TARGET_64BIT
+#define JUMP_TABLES_IN_TEXT_SECTION rs6000_relative_jumptables
+
+#undef JUMP_TABLES_IN_RELRO
+#define JUMP_TABLES_IN_RELRO !rs6000_relative_jumptables

The third choice is .rodata.  .data.rel.ro can be considered to be a
sub-case of that, but not the other way around.


+extern void rs6000_output_addr_vec_elt(FILE *, int);

(space before opening paren)


+/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC. Return true if 
rs6000_relative_jumptables is set. */

The maximum line length is 80 characters.  Two spaces after a full stop.


+/* Enable non-relative jump tables for linux ELF. */
+#ifdef TARGET_ELF
+#if !TARGET_AIX
+#undef rs6000_relative_jumptables
+#define rs6000_relative_jumptables 0
+#endif
+#endif

AIX never is ELF, but many other things *are* ELF.  Do all of those
handle .data.rel.ro, including do they have enough OS support for it?

This also changes the default for ELF systems?  Let's not do that (in
this patch, that is).


+/* Specify the machine mode that this machine uses
+   for the index in the tablejump instruction.  */
+#define CASE_VECTOR_MODE \
+  (TARGET_32BIT || rs6000_relative_jumptables ? SImode : DImode)

#define CASE_VECTOR_MODE (rs6000_relative_jumptables ? SImode : Pmode)


+/* This is how to output an element of a case-vector
+   that is non-relative. */

(no space at end of line; two spaces after full stop, also before */)


+#define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
+  rs6000_output_addr_vec_elt((FILE), (VALUE))

Space before first ( please (on the second line, on the first you
cannot -- macro definitions are the only exception).


diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 0aa5265d199..2f28da0ea1f 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -12669,18 +12669,32 @@
if (rs6000_speculate_indirect_jumps)
  {
if (TARGET_32BIT)
-   emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
-  else
+{
+  if (rs6000_relative_jumptables)
+emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
+  else
+   emit_jump_insn (gen_nonrelative_tablejumpsi (operands[0], 
operands[1]));

Please fix the indent while you're at it (tabs shouldn't follow spaces).
Oh, and line too long.


+}
+  else if (rs6000_relative_jumptables)
emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
+  else
+emit_jump_insn (gen_nonrelative_tablejumpdi (operands[0], 
operands[1]));

Please put the "relative" case on the outside, and the "32 or 64" if on
the inside.


+(define_expand "nonrelative_tablejumpsi"

Maybe call it "absolute_tablejumpsi"?  Not sure :-)


+   "TARGET_32BIT && rs6000_speculate_indirect_jumps && 
!rs6000_relative_jumptables"

Line too long (more follow, I won't point all out, please check :-) )


+ {
+  operands[2] = gen_reg_rtx (SImode);
+ })

No spaces before { and } here, those are flush left like in outer braces
in a C function are.


+(define_expand "nonrelative_tablejumpsi_nospec"
+  [(set (match_dup 3)
+(match_operand:SI 0 "gpc_reg_operand" "r"))
+   (parallel [(set (pc)
+   (match_dup 3))
+  (use (label_ref (match_operand 1)))
+  (clobber (match_operand 2))])]

Please use a leading tab instead of every 8 leading spaces.


I'll try to be quicker at reviewing iterations of this -- there is quite
some way to go, without me slowing things down!


Segher
* config/rs6000/linux.h (rs6000_relative_jumptables): Define.
* config/rs6000/linux64.h (JUMP_TABLES_IN_TEXT_SECTION,
rs6000_relative_jumptables): Define.
* config/rs6000/rs6000-protos.h (rs6000_output_addr_vec_elt): Declare.
* config/rs6000/rs6000.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC):
Define
(rs6000_gen_pic_addr_diff_vec, rs6000_output_addr_vec_elt): Implement.
* config/rs6000/rs6000.h (CASE_VECTOR_PC_RELATIVE,
CASE_VECTOR_MODE, 

Re: [PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-08-19 Thread Segher Boessenkool
Hi!

Sorry this took so long to review.  "I lost track of this patch", what
can I say :-/

On Fri, Aug 14, 2020 at 03:31:05PM +0800, HAO CHEN GUI wrote:
> This patch adds non-relative jump table support on Power Linux. It 
> implements ASM_OUTPUT_ADDR_VEC_ELT and adds four new expansions for 
> non-relative jump table in rs6000.md. It also defines a rs6000 
> option(mrelative-jumptables). If it's set to false, the non-relative 
> jump table is picked up even PIC flag is set.

> diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
> index 34776c8421e..626f2201d96 100644
> --- a/gcc/config/rs6000/linux64.h
> +++ b/gcc/config/rs6000/linux64.h
> @@ -324,7 +324,10 @@ extern int dot_symbols;
>  
>  /* Indicate that jump tables go in the text section.  */
>  #undef  JUMP_TABLES_IN_TEXT_SECTION
> -#define JUMP_TABLES_IN_TEXT_SECTION TARGET_64BIT
> +#define JUMP_TABLES_IN_TEXT_SECTION rs6000_relative_jumptables
> +
> +#undef JUMP_TABLES_IN_RELRO
> +#define JUMP_TABLES_IN_RELRO !rs6000_relative_jumptables

The third choice is .rodata.  .data.rel.ro can be considered to be a
sub-case of that, but not the other way around.

> +extern void rs6000_output_addr_vec_elt(FILE *, int);

(space before opening paren)

> +/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC. Return true if 
> rs6000_relative_jumptables is set. */

The maximum line length is 80 characters.  Two spaces after a full stop.

> +/* Enable non-relative jump tables for linux ELF. */
> +#ifdef TARGET_ELF
> +#if !TARGET_AIX 
> +#undef rs6000_relative_jumptables
> +#define rs6000_relative_jumptables 0
> +#endif
> +#endif

AIX never is ELF, but many other things *are* ELF.  Do all of those
handle .data.rel.ro, including do they have enough OS support for it?

This also changes the default for ELF systems?  Let's not do that (in
this patch, that is).

> +/* Specify the machine mode that this machine uses
> +   for the index in the tablejump instruction.  */
> +#define CASE_VECTOR_MODE \
> +  (TARGET_32BIT || rs6000_relative_jumptables ? SImode : DImode)

#define CASE_VECTOR_MODE (rs6000_relative_jumptables ? SImode : Pmode)

> +/* This is how to output an element of a case-vector 
> +   that is non-relative. */

(no space at end of line; two spaces after full stop, also before */)

> +#define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \
> +  rs6000_output_addr_vec_elt((FILE), (VALUE))

Space before first ( please (on the second line, on the first you
cannot -- macro definitions are the only exception).

> diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
> index 0aa5265d199..2f28da0ea1f 100644
> --- a/gcc/config/rs6000/rs6000.md
> +++ b/gcc/config/rs6000/rs6000.md
> @@ -12669,18 +12669,32 @@
>if (rs6000_speculate_indirect_jumps)
>  {
>if (TARGET_32BIT)
> - emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
> -  else
> +{
> +  if (rs6000_relative_jumptables)
> +emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
> +  else
> + emit_jump_insn (gen_nonrelative_tablejumpsi (operands[0], 
> operands[1]));

Please fix the indent while you're at it (tabs shouldn't follow spaces).
Oh, and line too long.

> +}
> +  else if (rs6000_relative_jumptables)
>   emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
> +  else 
> +emit_jump_insn (gen_nonrelative_tablejumpdi (operands[0], 
> operands[1]));

Please put the "relative" case on the outside, and the "32 or 64" if on
the inside.

> +(define_expand "nonrelative_tablejumpsi"

Maybe call it "absolute_tablejumpsi"?  Not sure :-)

> +   "TARGET_32BIT && rs6000_speculate_indirect_jumps && 
> !rs6000_relative_jumptables"

Line too long (more follow, I won't point all out, please check :-) )

> + {
> +  operands[2] = gen_reg_rtx (SImode);
> + })

No spaces before { and } here, those are flush left like in outer braces
in a C function are.

> +(define_expand "nonrelative_tablejumpsi_nospec"
> +  [(set (match_dup 3)
> +(match_operand:SI 0 "gpc_reg_operand" "r"))
> +   (parallel [(set (pc)
> +   (match_dup 3))
> +  (use (label_ref (match_operand 1)))
> +  (clobber (match_operand 2))])]

Please use a leading tab instead of every 8 leading spaces.


I'll try to be quicker at reviewing iterations of this -- there is quite
some way to go, without me slowing things down!


Segher


[PATCH, rs6000] Add non-relative jump table support on Power Linux

2020-08-14 Thread HAO CHEN GUI via Gcc-patches

Hi,

This patch adds non-relative jump table support on Power Linux. It 
implements ASM_OUTPUT_ADDR_VEC_ELT and adds four new expansions for 
non-relative jump table in rs6000.md. It also defines a rs6000 
option(mrelative-jumptables). If it's set to false, the non-relative 
jump table is picked up even PIC flag is set.


The attachments are the patch diff file and change log file.

Bootstrapped and tested on powerpc64le-linux-gnu with no regressions.  
Is this okay for trunk? Any recommendations? Thanks a lot.


* config/rs6000/linux64.h (JUMP_TABLES_IN_TEXT_SECTION, 
JUMP_TABLES_IN_RELRO): Define.
* config/rs6000/rs6000-protos.h (rs6000_output_addr_vec_elt): 
Declare.
* config/rs6000/rs6000.c (TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC, 
rs6000_gen_pic_addr_diff_vec, rs6000_output_addr_vec_elt): 
TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC define.
rs6000_gen_pic_addr_diff_vec, rs6000_output_addr_vec_elt 
implement.
* config/rs6000/rs6000.h (rs6000_relative_jumptables, 
CASE_VECTOR_PC_RELATIVE, 
CASE_VECTOR_MODE): Define.
* config/rs6000/rs6000.md (nonrelative_tablejumpsi, 
nonrelative_tablejumpsi_nospec, 
nonrelative_tablejumpdi, nonrelative_tablejumpdi_nospec): Add 
four new expansions.
* config/rs6000/rs6000.opt (mrelative-jumptables): A new option.diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
index 34776c8421e..626f2201d96 100644
--- a/gcc/config/rs6000/linux64.h
+++ b/gcc/config/rs6000/linux64.h
@@ -324,7 +324,10 @@ extern int dot_symbols;
 
 /* Indicate that jump tables go in the text section.  */
 #undef  JUMP_TABLES_IN_TEXT_SECTION
-#define JUMP_TABLES_IN_TEXT_SECTION TARGET_64BIT
+#define JUMP_TABLES_IN_TEXT_SECTION rs6000_relative_jumptables
+
+#undef JUMP_TABLES_IN_RELRO
+#define JUMP_TABLES_IN_RELRO !rs6000_relative_jumptables
 
 /* The linux ppc64 ABI isn't explicit on whether aggregates smaller
than a doubleword should be padded upward or downward.  You could
diff --git a/gcc/config/rs6000/rs6000-protos.h 
b/gcc/config/rs6000/rs6000-protos.h
index 5508484ba19..820943cdde0 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -155,6 +155,8 @@ extern void rs6000_split_logical (rtx [], enum rtx_code, 
bool, bool, bool);
 extern bool rs6000_pcrel_p (struct function *);
 extern bool rs6000_fndecl_pcrel_p (const_tree);
 
+extern void rs6000_output_addr_vec_elt(FILE *, int);
+
 /* Different PowerPC instruction formats that are used by GCC.  There are
various other instruction formats used by the PowerPC hardware, but these
formats are not currently used by GCC.  */
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 58f5d780603..0a149e3e99c 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -1369,6 +1369,9 @@ static const struct attribute_spec 
rs6000_attribute_table[] =
 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA rs6000_output_addr_const_extra
 
+#undef  TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC
+#define TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC rs6000_gen_pic_addr_diff_vec
+
 #undef TARGET_LEGITIMIZE_ADDRESS
 #define TARGET_LEGITIMIZE_ADDRESS rs6000_legitimize_address
 
@@ -26494,6 +26497,26 @@ rs6000_cannot_substitute_mem_equiv_p (rtx mem)
   return false;
 }
 
+/* Implement TARGET_ASM_GENERATE_PIC_ADDR_DIFF_VEC. Return true if 
rs6000_relative_jumptables is set. */
+
+static bool
+rs6000_gen_pic_addr_diff_vec (void)
+{
+  return rs6000_relative_jumptables;
+}
+
+void
+rs6000_output_addr_vec_elt (FILE *file, int value)
+{
+  const char *directive = TARGET_64BIT ? DOUBLE_INT_ASM_OP : "\t.long\t";
+  char buf[100];
+
+  fprintf(file, "%s", directive);
+  ASM_GENERATE_INTERNAL_LABEL (buf, "L", value);
+  assemble_name (file, buf);
+  fprintf(file, "\n");
+}
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-rs6000.h"
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index 1209a33173e..9254911836d 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -1752,15 +1752,25 @@ typedef struct rs6000_args
 
 /* #define LEGITIMATE_PIC_OPERAND_P (X) */
 
-/* Specify the machine mode that this machine uses
-   for the index in the tablejump instruction.  */
-#define CASE_VECTOR_MODE SImode
+
+/* Enable non-relative jump tables for linux ELF. */
+#ifdef TARGET_ELF
+#if !TARGET_AIX 
+#undef rs6000_relative_jumptables
+#define rs6000_relative_jumptables 0
+#endif
+#endif
 
 /* Define as C expression which evaluates to nonzero if the tablejump
instruction expects the table to contain offsets from the address of the
table.
Do not define this if the table should contain absolute addresses.  */
-#define CASE_VECTOR_PC_RELATIVE 1
+#define CASE_VECTOR_PC_RELATIVE 0
+
+/* Specify the machine mode that this machine uses
+   for the index in the