Be lazy about computing addresses in DWARF location expressions

Geoffrey Keating gkeating@apple.com
Wed Apr 26 06:56:00 GMT 2006


The write to dw_loc_addr causes copy-on-write events on PCH file
pages, which are expensive.  Since that field is only used when a
location expression contains a branch, and branches are rare (most
location expressions just say 'in register 3' or similar), it's
faster to avoid the write.

Actually, since GCC will only ever emit forward branches, you could
avoid even that little overhead from this patch by changing the second
loop to
  for (; l != NULL; l = l->dw_loc_next)
but that'd just create a trap for the first person who did want a
backwards branch, so I didn't do it.

Bootstrapped & tested on powerpc-darwin8 with DWARF on by default.

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/gcc-dwarf-lazylocsize.patch===============
2006-04-25  Geoffrey Keating  <geoffk@apple.com>

	* dwarf2out.c (size_of_locs): Don't fill dw_loc_addr if there
	are no branches.

Index: dwarf2out.c
===================================================================
--- dwarf2out.c	(revision 113241)
+++ dwarf2out.c	(working copy)
@@ -3228,14 +3228,26 @@
 static unsigned long
 size_of_locs (dw_loc_descr_ref loc)
 {
+  dw_loc_descr_ref l;
   unsigned long size;
 
-  for (size = 0; loc != NULL; loc = loc->dw_loc_next)
+  /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
+     field, to avoid writing to a PCH file.  */
+  for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
     {
-      loc->dw_loc_addr = size;
-      size += size_of_loc_descr (loc);
+      if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
+	break;
+      size += size_of_loc_descr (l);
     }
+  if (! l)
+    return size;
 
+  for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
+    {
+      l->dw_loc_addr = size;
+      size += size_of_loc_descr (l);
+    }
+
   return size;
 }
 
============================================================



More information about the Gcc-patches mailing list