[AIX] Optimize parsing of include files.

Message ID B37989F2852398498001550C29155BE5184ACDCC@FRCRPVV9EX3MSX.ww931.my-it-solutions.net
State New
Headers show
Series
  • [AIX] Optimize parsing of include files.
Related show

Commit Message

REIX, Tony Jan. 18, 2018, 2:56 p.m.
Description:
 * This patch optimizes the time required for parsing the include files.

Tests:
 * AIX: Build: SUCCESS
   - build made by means of gmake on AIX.

ChangeLog:
  * xcoff.c: Optimize parsing of include files.



Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net

Comments

David Edelsohn Jan. 19, 2018, 4:36 p.m. | #1
On Thu, Jan 18, 2018 at 9:56 AM, REIX, Tony <tony.reix@atos.net> wrote:
>

> Description:

>  * This patch optimizes the time required for parsing the include files.

>

> Tests:

>  * AIX: Build: SUCCESS

>    - build made by means of gmake on AIX.

>

> ChangeLog:

>   * xcoff.c: Optimize parsing of include files.


Hi, Tony

The ChangeLog should be more detailed.

* xcoff.c (xcoff_incl_compare): New function.
(xcoff_incl_search): New function.
(xcoff_process_linenos): Use bsearch to find include file.
(xcoff_initialize_fileline): Sort include file information.


The rest is okay, although the calls to bsearch and backtrace_qsort
don't follow the style of other files.

This is okay.

Thanks, David
REIX, Tony Jan. 19, 2018, 5:13 p.m. | #2
Thanks David,

I've saved you comments in our Wiki so I hope I'll remember and do better next time.

Regards,

Cordialement,

Tony Reix

ATOS / Bull SAS
ATOS Expert
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net

________________________________________
De : David Edelsohn [dje.gcc@gmail.com]
Envoyé : vendredi 19 janvier 2018 17:36
À : REIX, Tony
Cc : gcc-patches@gcc.gnu.org; Ian Lance Taylor; BERGAMINI, DAMIEN
Objet : Re: [PATCH,AIX] Optimize parsing of include files.

On Thu, Jan 18, 2018 at 9:56 AM, REIX, Tony <tony.reix@atos.net> wrote:
>

> Description:

>  * This patch optimizes the time required for parsing the include files.

>

> Tests:

>  * AIX: Build: SUCCESS

>    - build made by means of gmake on AIX.

>

> ChangeLog:

>   * xcoff.c: Optimize parsing of include files.


Hi, Tony

The ChangeLog should be more detailed.

* xcoff.c (xcoff_incl_compare): New function.
(xcoff_incl_search): New function.
(xcoff_process_linenos): Use bsearch to find include file.
(xcoff_initialize_fileline): Sort include file information.


The rest is okay, although the calls to bsearch and backtrace_qsort
don't follow the style of other files.

This is okay.

Thanks, David
Ian Lance Taylor Jan. 19, 2018, 5:45 p.m. | #3
On Fri, Jan 19, 2018 at 8:36 AM, David Edelsohn <dje.gcc@gmail.com> wrote:
> On Thu, Jan 18, 2018 at 9:56 AM, REIX, Tony <tony.reix@atos.net> wrote:

>>

>> Description:

>>  * This patch optimizes the time required for parsing the include files.

>>

>> Tests:

>>  * AIX: Build: SUCCESS

>>    - build made by means of gmake on AIX.

>>

>> ChangeLog:

>>   * xcoff.c: Optimize parsing of include files.

>

> Hi, Tony

>

> The ChangeLog should be more detailed.

>

> * xcoff.c (xcoff_incl_compare): New function.

> (xcoff_incl_search): New function.

> (xcoff_process_linenos): Use bsearch to find include file.

> (xcoff_initialize_fileline): Sort include file information.

>

>

> The rest is okay, although the calls to bsearch and backtrace_qsort

> don't follow the style of other files.

>

> This is okay.


I committed the patch with that ChangeLog entry.

Ian

Patch

Index: libbacktrace/xcoff.c
===================================================================
--- libbacktrace/xcoff.c	(revision 256837)
+++ libbacktrace/xcoff.c	(working copy)
@@ -760,6 +760,40 @@  xcoff_fileline (struct backtrace_state *state, uin
   return callback (data, pc, NULL, 0, NULL);
 }
 
+/* Compare struct xcoff_incl for qsort.  */
+
+static int
+xcoff_incl_compare (const void *v1, const void *v2)
+{
+  const struct xcoff_incl *in1 = (const struct xcoff_incl *) v1;
+  const struct xcoff_incl *in2 = (const struct xcoff_incl *) v2;
+
+  if (in1->begin < in2->begin)
+    return -1;
+  else if (in1->begin > in2->begin)
+    return 1;
+  else
+    return 0;
+}
+
+/* Find a lnnoptr in an include file.  */
+
+static int
+xcoff_incl_search (const void *vkey, const void *ventry)
+{
+  const uintptr_t *key = (const uintptr_t *) vkey;
+  const struct xcoff_incl *entry = (const struct xcoff_incl *) ventry;
+  uintptr_t lnno;
+
+  lnno = *key;
+  if (lnno < entry->begin)
+    return -1;
+  else if (lnno > entry->end)
+    return 1;
+  else
+    return 0;
+}
+
 /* Add a new mapping to the vector of line mappings that we are
    building.  Returns 1 on success, 0 on failure.  */
 
@@ -809,7 +843,6 @@  xcoff_process_linenos (struct backtrace_state *sta
   uintptr_t pc;
   uint32_t lnno;
   int begincl;
-  size_t i;
 
   aux = (const b_xcoff_auxent *) (fsym + 1);
   lnnoptr = aux->x_fcn.x_lnnoptr;
@@ -839,15 +872,13 @@  xcoff_process_linenos (struct backtrace_state *sta
       /* If part of a function other than the beginning comes from an
 	 include file, the line numbers are absolute, rather than
 	 relative to the beginning of the function.  */
-      for (i = 0; i < vec->count; ++i)
-	{
-	  incl = (struct xcoff_incl *) vec->vec.base + i;
-	  if (incl->begin <= lnnoptr && lnnoptr <= incl->end)
-	    break;
-	}
+      incl = (struct xcoff_incl *) bsearch (&lnnoptr, vec->vec.base,
+					    vec->count,
+					    sizeof (struct xcoff_incl),
+					    xcoff_incl_search);
       if (begincl == -1)
-	begincl = (i < vec->count);
-      if (i < vec->count)
+	begincl = incl != NULL;
+      if (incl != NULL)
 	{
 	  filename = incl->filename;
 	  if (begincl == 1)
@@ -935,6 +966,9 @@  xcoff_initialize_fileline (struct backtrace_state
       i += asym->n_numaux;
     }
 
+  backtrace_qsort (vec.vec.base, vec.count,
+		   sizeof (struct xcoff_incl), xcoff_incl_compare);
+
   filename = NULL;
   fsym = NULL;
   for (i = 0; i < nsyms; ++i)