Gcc extra alignment..

Richard Henderson rth@cygnus.com
Wed Nov 1 02:29:00 GMT 2000


On Wed, Nov 01, 2000 at 09:55:31AM +0100, Christian Iseli wrote:
> I'm afraid things are not quite that simple.  I'm pretty sure people used
> the break statement to get out early of those phony loops.

Sigh, yes indeed.  This one actually survived a bootstrap.


r~


        * stmt.c (expand_start_null_loop): New.
        (expand_end_null_loop): New.
        * c-semantics.c (genrtl_do_stmt): Use them.
        * tree.h: Declare them.

Index: c-semantics.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-semantics.c,v
retrieving revision 1.12
diff -c -p -d -r1.12 c-semantics.c
*** c-semantics.c	2000/11/01 01:48:12	1.12
--- c-semantics.c	2000/11/01 10:26:58
*************** genrtl_do_stmt (t)
*** 487,493 ****
       avoids cluttering the rtl with dummy loop notes, which can affect
       alignment of adjacent labels.  */
    if (integer_zerop (cond))
!     expand_stmt (DO_BODY (t));
    else
      {
        emit_nop ();
--- 487,497 ----
       avoids cluttering the rtl with dummy loop notes, which can affect
       alignment of adjacent labels.  */
    if (integer_zerop (cond))
!     {
!       expand_start_null_loop ();
!       expand_stmt (DO_BODY (t));
!       expand_end_null_loop ();
!     }
    else
      {
        emit_nop ();
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/stmt.c,v
retrieving revision 1.171
diff -c -p -d -r1.171 stmt.c
*** stmt.c	2000/10/13 06:26:28	1.171
--- stmt.c	2000/11/01 10:26:58
*************** expand_start_loop_continue_elsewhere (ex
*** 2294,2299 ****
--- 2294,2323 ----
    return thisloop;
  }
  
+ /* Begin a null, aka do { } while (0) "loop".  But since the contents
+    of said loop can still contain a break, we must frob the loop nest.  */
+ 
+ struct nesting *
+ expand_start_null_loop ()
+ {
+   register struct nesting *thisloop = ALLOC_NESTING ();
+ 
+   /* Make an entry on loop_stack for the loop we are entering.  */
+ 
+   thisloop->next = loop_stack;
+   thisloop->all = nesting_stack;
+   thisloop->depth = ++nesting_depth;
+   thisloop->data.loop.start_label = emit_note (NULL, NOTE_INSN_DELETED);
+   thisloop->data.loop.end_label = gen_label_rtx ();
+   thisloop->data.loop.alt_end_label = NULL_RTX;
+   thisloop->data.loop.continue_label = NULL_RTX;
+   thisloop->exit_label = thisloop->data.loop.end_label;
+   loop_stack = thisloop;
+   nesting_stack = thisloop;
+ 
+   return thisloop;
+ }
+ 
  /* Specify the continuation point for a loop started with
     expand_start_loop_continue_elsewhere.
     Use this at the point in the code to which a continue statement
*************** expand_end_loop ()
*** 2613,2618 ****
--- 2637,2655 ----
        emit_jump (start_label);
        emit_note (NULL_PTR, NOTE_INSN_LOOP_END);
      }
+   emit_label (loop_stack->data.loop.end_label);
+ 
+   POPSTACK (loop_stack);
+ 
+   last_expr_type = 0;
+ }
+ 
+ /* Finish a null loop, aka do { } while (0).  */
+ 
+ void
+ expand_end_null_loop ()
+ {
+   do_pending_stack_adjust ();
    emit_label (loop_stack->data.loop.end_label);
  
    POPSTACK (loop_stack);
Index: tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tree.h,v
retrieving revision 1.207
diff -c -p -d -r1.207 tree.h
*** tree.h	2000/10/23 04:40:25	1.207
--- tree.h	2000/11/01 10:26:58
*************** extern void expand_start_else			PARAMS (
*** 2460,2467 ****
--- 2460,2469 ----
  extern void expand_start_elseif			PARAMS ((tree));
  extern struct nesting *expand_start_loop 	PARAMS ((int));
  extern struct nesting *expand_start_loop_continue_elsewhere 	PARAMS ((int));
+ extern struct nesting *expand_start_null_loop 	PARAMS ((void));
  extern void expand_loop_continue_here		PARAMS ((void));
  extern void expand_end_loop			PARAMS ((void));
+ extern void expand_end_null_loop		PARAMS ((void));
  extern int expand_continue_loop			PARAMS ((struct nesting *));
  extern int expand_exit_loop			PARAMS ((struct nesting *));
  extern int expand_exit_loop_if_false		PARAMS ((struct nesting *,


More information about the Gcc-patches mailing list