This is the mail archive of the gcc-patches@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]

[patch] Why 300-line functions are bad.


300 lines is the approximate length of purge_addressof_1 in
function.c, which reads like this:

	if (code == SET)
	  ... 3 lines ... 
	else if (code == ADDRESSOF && ...)
	  ... 30 lines ...
	else if (code == MEM && ...)
	  ... 200 lines ...
	else if (code == ADDRESSOF)
	  ... 2 lines ...
	else if (code == SET)
	  ... 3 lines ...

Guess what - the two (code == SET) blocks are identical.  I can't tell
how long it's been like this, at least since 1999, and I bet no one's
noticed in all this time because the top and bottom of the if sequence
were never visible at once.

Suggestions for a more coherent change log would be appreciated.

zw

	* function.c (purge_addressof_1): Remove redundant if block.
	Fold if (code == ADDRESSOF) block below 200-line if block into
	if (code == ADDRESSOF) block above 200-line if block.

===================================================================
Index: function.c
--- function.c	2001/04/20 07:56:50	1.265
+++ function.c	2001/04/25 04:32:42
@@ -2991,14 +2991,19 @@ purge_addressof_1 (loc, insn, force, sto
       result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
       return result;
     }
-
-  else if (code == ADDRESSOF && GET_CODE (XEXP (x, 0)) == MEM)
+  else if (code == ADDRESSOF)
     {
+      rtx sub, insns;
+
+      if (GET_CODE (XEXP (x, 0)) != MEM)
+	{
+	  put_addressof_into_stack (x, ht);
+	  return true;
+	}
+	  
       /* We must create a copy of the rtx because it was created by
 	 overwriting a REG rtx which is always shared.  */
-      rtx sub = copy_rtx (XEXP (XEXP (x, 0), 0));
-      rtx insns;
-
+      sub = copy_rtx (XEXP (XEXP (x, 0), 0));
       if (validate_change (insn, loc, sub, 0)
 	  || validate_replace_rtx (x, sub, insn))
 	return true;
@@ -3210,22 +3215,9 @@ purge_addressof_1 (loc, insn, force, sto
 	    }
 	  goto restart;
 	}
-    give_up:;
-      /* else give up and put it into the stack */
-    }
-
-  else if (code == ADDRESSOF)
-    {
-      put_addressof_into_stack (x, ht);
-      return true;
-    }
-  else if (code == SET)
-    {
-      result = purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
-      result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
-      return result;
     }
 
+ give_up:
   /* Scan all subexpressions.  */
   fmt = GET_RTX_FORMAT (code);
   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)


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