* config/rs6000/rs6000.c (rs6000_emit_prologue): Update for change
authorgeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 Sep 2002 18:42:24 +0000 (18:42 +0000)
committergeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 20 Sep 2002 18:42:24 +0000 (18:42 +0000)
to load_macho_picbase.
* config/rs6000/rs6000.md: Document Darwin-specific unspec IDs.
(load_macho_picbase): Take the symbol to use as a parameter.
(macho_correct_pic): New insn.
(builtin_setjmp_reciever): On Darwin, restore the PIC register.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@57360 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/config/rs6000/rs6000.c
gcc/config/rs6000/rs6000.md

index 59da956..7dfdfa0 100644 (file)
@@ -1,5 +1,12 @@
 2002-09-20  Geoffrey Keating  <geoffk@apple.com>
 
+       * config/rs6000/rs6000.c (rs6000_emit_prologue): Update for change
+       to load_macho_picbase.
+       * config/rs6000/rs6000.md: Document Darwin-specific unspec IDs.
+       (load_macho_picbase): Take the symbol to use as a parameter.
+       (macho_correct_pic): New insn.
+       (builtin_setjmp_reciever): On Darwin, restore the PIC register.
+
        * config/rs6000/rs6000.h (ELIMINABLE_REGS): Use
        RS6000_PIC_OFFSET_TABLE_REGNUM rather than hardcoding 30.
        (CAN_ELIMINATE): Likewise.
index ba0249c..909dc6b 100644 (file)
@@ -10458,8 +10458,12 @@ rs6000_emit_prologue ()
       && flag_pic && current_function_uses_pic_offset_table)
     {
       rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
+#if TARGET_MACHO
+      char *picbase = machopic_function_base_name ();
+      rtx src = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (picbase, -1));
 
-      rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest)));
+      rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
+#endif
 
       rs6000_maybe_dead (
        emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
index 8bfec08..e85dc53 100644 (file)
@@ -1,6 +1,6 @@
 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
 ;; Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 
-;; 1999, 2000, 2001 Free Software Foundation, Inc.
+;; 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
 
 ;; This file is part of GNU CC.
@@ -32,6 +32,8 @@
 ;; 8           movsi_got
 ;; 9/v         eh_reg_restore
 ;; 10          fctiwz
+;; 15          load_macho_picbase
+;; 16          macho_correct_pic
 ;; 19          movesi_from_cr
 ;; 20          movesi_to_cr
 \f
 
 (define_insn "load_macho_picbase"
   [(set (match_operand:SI 0 "register_operand" "=l")
-       (unspec:SI [(const_int 0)] 15))]
+       (unspec:SI [(match_operand:SI 1 "immediate_operand" "s")] 15))]
   "(DEFAULT_ABI == ABI_DARWIN) && flag_pic"
-  "*
-{
-#if TARGET_MACHO
-  char *picbase = machopic_function_base_name ();
-  operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (picbase, -1));
-#endif
-  return \"bcl 20,31,%1\\n%1:\";
-}"
+  "bcl 20,31,%1\\n%1:"
   [(set_attr "type" "branch")
    (set_attr "length" "4")])
 
+(define_insn "macho_correct_pic"
+  [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
+       (plus:SI (match_operand:SI 1 "gpc_reg_operand" "=r")
+                (unspec:SI [(match_operand:SI 2 "immediate_operand" "s")
+                            (match_operand:SI 3 "immediate_operand" "s")]
+                           16)))]
+  "DEFAULT_ABI == ABI_DARWIN"
+  "addis %0,%1,ha16(%2-%3)\n\taddi %1,%1,lo16(%2-%3)"
+  [(set_attr "length" "8")])
+
 ;; If the TOC is shared over a translation unit, as happens with all
 ;; the kinds of PIC that we support, we need to restore the TOC
 ;; pointer only when jumping over units of translation.
+;; On Darwin, we need to reload the picbase.
 
 (define_expand "builtin_setjmp_receiver"
   [(use (label_ref (match_operand 0 "" "")))]
   "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
-   || (TARGET_TOC && TARGET_MINIMAL_TOC)"
+   || (TARGET_TOC && TARGET_MINIMAL_TOC)
+   || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
   "
 {
-  rs6000_emit_load_toc_table (FALSE);
+  if (DEFAULT_ABI == ABI_DARWIN)
+    {
+      char *picbase = machopic_function_base_name ();
+      rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (picbase, -1));
+      rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
+      rtx tmplabrtx;
+      char tmplab[20];
+
+      ASM_GENERATE_INTERNAL_LABEL(tmplab, \"LSJR\",
+                                 CODE_LABEL_NUMBER (operands[0]));
+      tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (tmplab, -1));
+
+      emit_insn (gen_load_macho_picbase (picreg, tmplabrtx));
+      emit_insn (gen_macho_correct_pic (picreg, picreg, picrtx, tmplabrtx));
+    }
+  else
+    rs6000_emit_load_toc_table (FALSE);
   DONE;
 }")
 \f