This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Does weak work on PPC with -O2?


On Tuesday 13 March 2001 00:27, Geoff Keating wrote:
> Franz Sirl <Franz.Sirl-kernel@lauterbach.com> writes:
> > Well, contrary to my first believe the fix might be really simple,
> > AFAICS the relevant piece of code is in make_decl_rtl in varasm.c,
> > or? If we set the RTX VOLATILE flag (which is so far unused for
> > SYMBOL_REF) for DECL_WEAK symbols, we should be set. Then we can
> > just test SYMBOL_REF_WEAK at the relevant places (there are some
> > places where some less important optimizations are explicitly
> > disabled because of the weak symbol problem) and be happy. Or are
> > there any pitfalls in this simple plan? There must be, or why wasn't
> > it fixed til now?
>
> Hey, that's really clever.  I didn't think of using VOLATILE.  It
> even makes sense...

And it seems to work nicely with the testcase :-). I think I need to use 
FRAME_RELATED as a flag though, cause VOLATIL is already used for 
SYMBOL_REF_FLAG, I overlooked that. I'll try to bootstrap the appended 
minimum patch for the gcc-2_95-branch. If that works, I'll port it to 
mainline and gcc-3_0-branch, with all the other temporarily disabled 
optimizations enabled.

> > Naturally the same has to be done for weak LABEL_REF's, too.
>
> It's not clear to me how a LABEL_REF can meaningfully be weak.
> Doesn't it always have to be defined in the same procedure?

I got confused, forget it.

Franz.

	* rtl.h (SYMBOL_REF_WEAK): New macro.
	* varasm.c (make_decl_rtl): Set SYMBOL_REF_WEAK for weak symbols.
	* rtlanal.c (rtx_addr_can_trap_p): A weak SYMBOL_REF can trap.

Index: gcc/rtl.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/rtl.h,v
retrieving revision 1.105.4.3
diff -u -p -r1.105.4.3 rtl.h
--- gcc/rtl.h	2001/01/25 14:03:22	1.105.4.3
+++ gcc/rtl.h	2001/03/13 01:03:58
@@ -168,7 +168,8 @@ typedef struct rtx_def
      either changing how we compute the frame address or saving and
      restoring registers in the prologue and epilogue.  
      1 in a MEM if the MEM refers to a scalar, rather than a member of
-     an aggregate.  */
+     an aggregate.
+     1 in a SYMBOL_REF if the symbol is weak.  */
   unsigned frame_related : 1;
   /* The first element of the operands of this rtx.
      The number of operands and their types are controlled
@@ -661,6 +662,9 @@ extern char *note_insn_name[];
 /* 1 means a SYMBOL_REF has been the library function in emit_library_call.  */
 #define SYMBOL_REF_USED(RTX) ((RTX)->used)
 
+/* 1 means a SYMBOL_REF is weak.  */
+#define SYMBOL_REF_WEAK(RTX) ((RTX)->frame_related)
+
 /* For an INLINE_HEADER rtx, FIRST_FUNCTION_INSN is the first insn
    of the function that is not involved in copying parameters to
    pseudo-registers.  FIRST_PARM_INSN is the very first insn of
Index: gcc/rtlanal.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/rtlanal.c,v
retrieving revision 1.36.4.2
diff -u -p -r1.36.4.2 rtlanal.c
--- gcc/rtlanal.c	2001/01/25 14:03:22	1.36.4.2
+++ gcc/rtlanal.c	2001/03/13 01:04:00
@@ -136,11 +136,9 @@ rtx_addr_can_trap_p (x)
   switch (code)
     {
     case SYMBOL_REF:
+      return SYMBOL_REF_WEAK (x);
+
     case LABEL_REF:
-      /* SYMBOL_REF is problematic due to the possible presence of
-	 a #pragma weak, but to say that loads from symbols can trap is
-	 *very* costly.  It's not at all clear what's best here.  For
-	 now, we ignore the impact of #pragma weak.  */
       return 0;
 
     case REG:
Index: gcc/varasm.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/varasm.c,v
retrieving revision 1.59.4.6
diff -u -p -r1.59.4.6 varasm.c
--- gcc/varasm.c	2001/01/25 14:03:24	1.59.4.6
+++ gcc/varasm.c	2001/03/13 01:04:04
@@ -723,6 +723,8 @@ make_decl_rtl (decl, asmspec, top_level)
 	 Also handle vars declared register invalidly.  */
       if (DECL_RTL (decl) == 0)
 	{
+	  rtx x;
+
 	  /* Can't use just the variable's own name for a variable
 	     whose scope is less than the whole file.
 	     Concatenate a distinguishing number.  */
@@ -752,8 +754,10 @@ make_decl_rtl (decl, asmspec, top_level)
 	      			   new_name, strlen (new_name));
 	    }
 
-	  DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
-					 gen_rtx_SYMBOL_REF (Pmode, name));
+	  x = gen_rtx_SYMBOL_REF (Pmode, name);
+	  SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
+	  DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl), x);
+	  
 	  MEM_ALIAS_SET (DECL_RTL (decl)) = get_alias_set (decl);
 	    
 	  /* If this variable is to be treated as volatile, show its

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]