public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [gcc-in-cxx] replacing qsort with std::sort
@ 2009-08-12  9:59 Pedro Lamarão
  2009-08-12 13:12 ` Richard Guenther
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Pedro Lamarão @ 2009-08-12  9:59 UTC (permalink / raw)
  To: gcc

I've recently started my contributions to the gcc-in-cxx project, and
eventually decided on the qsort suggestion because it seems the
easiest one.
I've made the change in three places in cp/classes.c; the patch can be
found here:

  http://code.google.com/p/ccppbrasil/wiki/GccInCxx

Is this the way to go?

Some questions occurred to me: in order to support a C and a C++
compiler at the same time, what "portability" mechanism should be
used? #ifdef guards to switch between qsort and std::sort on the spot,
based on __cplusplus? Should a helper function be declared somewhere?

Also, std::sort requires a "less" function on reference-tovalue-type,
so the current foo_cmp functions can't be reused.
Would a separate patch to introduce foo_less variants be acceptable
for GCC 4.5 right now?

Also, is the gcc-in-cxx branch still active? Should my objective be to
contribute patches to this branch?

On a side note, I've studied vec.h and found it hard to change.
One reason is because this header is included by the gen*.c stuff,
which is still being compiled by a C compiler, even when building with
a C++ compiler is enabled.
I've considered providing a separate version of vec.h when C++ is
being used, to avoid infinite #ifdefs.
Is this a good idea?

--
 Pedro Lamarão

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-12  9:59 [gcc-in-cxx] replacing qsort with std::sort Pedro Lamarão
@ 2009-08-12 13:12 ` Richard Guenther
  2009-08-12 14:33   ` Pedro Lamarão
  2009-08-12 13:21 ` Ian Lance Taylor
  2009-08-29 11:26 ` Pedro Lamarão
  2 siblings, 1 reply; 15+ messages in thread
From: Richard Guenther @ 2009-08-12 13:12 UTC (permalink / raw)
  To: Pedro Lamarão; +Cc: gcc

On Wed, Aug 12, 2009 at 2:03 AM, Pedro
Lamarão<pedro.lamarao@ccppbrasil.org> wrote:
> I've recently started my contributions to the gcc-in-cxx project, and
> eventually decided on the qsort suggestion because it seems the
> easiest one.
> I've made the change in three places in cp/classes.c; the patch can be
> found here:
>
>   http://code.google.com/p/ccppbrasil/wiki/GccInCxx
>
> Is this the way to go?

Please attach patches in the future.

+bool
+field_decl_less (const tree& x_p, const tree& y_p)
+{

you should be able to use std::bind and functors to avoid that
function.

+#include <algorithm>
+
 #include "config.h"
 #include "system.h"

The includes need to come after config.h and system.h at least.

+static bool
+method_name_less (const tree& m1_p, const tree& m2_p)

see above.

-      qsort (VEC_address (tree, method_vec) + slot, len - slot, sizeof (tree),
-            resort_method_name_cmp);
+      std::sort (VEC_address (tree, method_vec) + slot,
+            VEC_address (tree, method_vec) + len,
+            resort_method_name_less);

this hints at the fact that we want to replace VEC ...

> Some questions occurred to me: in order to support a C and a C++
> compiler at the same time, what "portability" mechanism should be
> used? #ifdef guards to switch between qsort and std::sort on the spot,
> based on __cplusplus? Should a helper function be declared somewhere?

We shouldn't do this kind of patches as long as we need to support
a C compiler.

> Also, std::sort requires a "less" function on reference-tovalue-type,
> so the current foo_cmp functions can't be reused.
> Would a separate patch to introduce foo_less variants be acceptable
> for GCC 4.5 right now?

No, I don't see the need for them.

> Also, is the gcc-in-cxx branch still active? Should my objective be to
> contribute patches to this branch?

I think the branch is dead, but you need to ask Ian.

> On a side note, I've studied vec.h and found it hard to change.
> One reason is because this header is included by the gen*.c stuff,
> which is still being compiled by a C compiler, even when building with
> a C++ compiler is enabled.
> I've considered providing a separate version of vec.h when C++ is
> being used, to avoid infinite #ifdefs.
> Is this a good idea?

See above.

Richard.

> --
>  Pedro Lamarão
>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-12  9:59 [gcc-in-cxx] replacing qsort with std::sort Pedro Lamarão
  2009-08-12 13:12 ` Richard Guenther
@ 2009-08-12 13:21 ` Ian Lance Taylor
  2009-08-29 11:26 ` Pedro Lamarão
  2 siblings, 0 replies; 15+ messages in thread
From: Ian Lance Taylor @ 2009-08-12 13:21 UTC (permalink / raw)
  To: Pedro Lamarão; +Cc: gcc

Pedro Lamarão <pedro.lamarao@ccppbrasil.org> writes:

> Also, is the gcc-in-cxx branch still active? Should my objective be to
> contribute patches to this branch?

The gcc-in-cxx branch is currently dead, having been merged into
mainline.  We can choose to revive it for contributions like yours.  I
would be interested in opinions from other developers on the best
approach here.


> On a side note, I've studied vec.h and found it hard to change.
> One reason is because this header is included by the gen*.c stuff,
> which is still being compiled by a C compiler, even when building with
> a C++ compiler is enabled.
> I've considered providing a separate version of vec.h when C++ is
> being used, to avoid infinite #ifdefs.
> Is this a good idea?

No.  We should instead have the gen*.c code built with C++.

Ian

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-12 13:12 ` Richard Guenther
@ 2009-08-12 14:33   ` Pedro Lamarão
  0 siblings, 0 replies; 15+ messages in thread
From: Pedro Lamarão @ 2009-08-12 14:33 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc

2009/8/12 Richard Guenther <richard.guenther@gmail.com>:

> On Wed, Aug 12, 2009 at 2:03 AM, Pedro
> Lamarão<pedro.lamarao@ccppbrasil.org> wrote:
>> I've recently started my contributions to the gcc-in-cxx project, and
>> eventually decided on the qsort suggestion because it seems the
>> easiest one.
>> I've made the change in three places in cp/classes.c; the patch can be
>> found here:
>>
>>   http://code.google.com/p/ccppbrasil/wiki/GccInCxx
>>
>> Is this the way to go?
>
> Please attach patches in the future.


Sorry.
I thought policy on this list was against attachments.


> +#include <algorithm>
> +
>  #include "config.h"
>  #include "system.h"
>
> The includes need to come after config.h and system.h at least.


I agree, but including <algorithm> last causes many "poisoned"
warnings that I don't understand -- using names like "calloc".


>> Also, std::sort requires a "less" function on reference-tovalue-type,
>> so the current foo_cmp functions can't be reused.
>> Would a separate patch to introduce foo_less variants be acceptable
>> for GCC 4.5 right now?
>
> No, I don't see the need for them.


I'll maintain these changes elsewhere, then.
Will GCC ever require support for both a C and a C++ compiler at the same time?
If it is reasonable to assume a C++ compiler things become easier for me.

--
 P.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-12  9:59 [gcc-in-cxx] replacing qsort with std::sort Pedro Lamarão
  2009-08-12 13:12 ` Richard Guenther
  2009-08-12 13:21 ` Ian Lance Taylor
@ 2009-08-29 11:26 ` Pedro Lamarão
  2009-08-29 19:42   ` Magnus Fromreide
  2009-08-31 19:06   ` Pedro Lamarão
  2 siblings, 2 replies; 15+ messages in thread
From: Pedro Lamarão @ 2009-08-29 11:26 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 850 bytes --]

2009/8/11 Pedro Lamarão <pedro.lamarao@ccppbrasil.org>:

> I've recently started my contributions to the gcc-in-cxx project, and
> eventually decided on the qsort suggestion because it seems the
> easiest one.

Attached is a much more extensive patch replacing qsort with std::sort.

I did not follow the suggestion of using bind to reuse the old
comparison functions.
Their "less" variants require less address taking and dereferencing
and are much smaller.
These functions are used at only one or two places, each of them --
perfect for inlining.
This patch actually reduces the size of the final binary.

I have not yet made complete size and execution speed measurements, though.
I've run the test suite and there are some failures; I think many of
them are not regressions when compared with a pure build with C++.

--
 P.

[-- Attachment #2: std_sort.patch --]
[-- Type: application/octet-stream, Size: 88695 bytes --]


Mudanças de propriedades em: .
___________________________________________________________________
Added: svn:ignore
   + obj


Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c	(revisão 4)
+++ gcc/tree-vrp.c	(cópia de trabalho)
@@ -38,6 +38,7 @@
 #include "tree-ssa-propagate.h"
 #include "tree-chrec.h"
 
+#include <algorithm>
 
 /* Set of SSA names found live during the RPO traversal of the function
    for still active basic-blocks.  */
@@ -4437,28 +4438,26 @@
 /* Compare two case labels sorting first by the destination label uid
    and then by the case value.  */
 
-static int
-compare_case_labels (const void *p1, const void *p2)
+static bool
+compare_case_labels (const tree& case1, const tree& case2)
 {
-  const_tree const case1 = *(const_tree const*)p1;
-  const_tree const case2 = *(const_tree const*)p2;
   unsigned int uid1 = DECL_UID (CASE_LABEL (case1));
   unsigned int uid2 = DECL_UID (CASE_LABEL (case2));
 
   if (uid1 < uid2)
-    return -1;
+    return true;
   else if (uid1 == uid2)
     {
       /* Make sure the default label is first in a group.  */
       if (!CASE_LOW (case1))
-	return -1;
+	return true;
       else if (!CASE_LOW (case2))
-	return 1;
+	return false;
       else
-        return tree_int_cst_compare (CASE_LOW (case1), CASE_LOW (case2));
+        return tree_int_cst_compare (CASE_LOW (case1), CASE_LOW (case2)) < 0;
     }
   else
-    return 1;
+    return false;
 }
 
 /* Determine whether the outgoing edges of BB should receive an
@@ -4495,7 +4494,8 @@
   vec2 = make_tree_vec (n);
   for (idx = 0; idx < n; ++idx)
     TREE_VEC_ELT (vec2, idx) = gimple_switch_label (last, idx);
-  qsort (&TREE_VEC_ELT (vec2, 0), n, sizeof (tree), compare_case_labels);
+  std::sort (&TREE_VEC_ELT (vec2, 0), &TREE_VEC_ELT (vec2, 0) + n,
+          compare_case_labels);
 
   for (idx = 0; idx < n; ++idx)
     {
Index: gcc/tree-into-ssa.c
===================================================================
--- gcc/tree-into-ssa.c	(revisão 4)
+++ gcc/tree-into-ssa.c	(cópia de trabalho)
@@ -49,6 +49,7 @@
 #include "params.h"
 #include "vecprim.h"
 
+#include <algorithm>
 
 /* This file builds the SSA form for a function as described in:
    R. Cytron, J. Ferrante, B. Rosen, M. Wegman, and K. Zadeck. Efficiently
@@ -791,13 +792,10 @@
 /* Compares two entries of type struct dom_dfsnum by dfs_num field.  Callback
    for qsort.  */
 
-static int
-cmp_dfsnum (const void *a, const void *b)
+static bool
+cmp_dfsnum (const dom_dfsnum& a, const dom_dfsnum& b)
 {
-  const struct dom_dfsnum *const da = (const struct dom_dfsnum *) a;
-  const struct dom_dfsnum *const db = (const struct dom_dfsnum *) b;
-
-  return (int) da->dfs_num - (int) db->dfs_num;
+  return (int) a.dfs_num < (int) b.dfs_num;
 }
 
 /* Among the intervals starting at the N points specified in DEFS, find
@@ -889,7 +887,7 @@
     }
   BITMAP_FREE (to_remove);
   gcc_assert (adef == 2 * n_defs + 1);
-  qsort (defs, adef, sizeof (struct dom_dfsnum), cmp_dfsnum);
+  std::sort (defs, defs + adef, cmp_dfsnum);
   gcc_assert (defs[0].bb_index == 1);
 
   /* Now each DEFS entry contains the number of the basic block to that the
Index: gcc/ddg.c
===================================================================
--- gcc/ddg.c	(revisão 4)
+++ gcc/ddg.c	(cópia de trabalho)
@@ -44,6 +44,8 @@
 #include "bitmap.h"
 #include "ddg.h"
 
+#include <algorithm>
+
 #ifdef INSN_SCHEDULING
 
 /* A flag indicating that a ddg edge belongs to an SCC or not.  */
@@ -851,12 +853,12 @@
 
 /* Compare function to be passed to qsort to order the backarcs in descending
    recMII order.  */
-static int
-compare_sccs (const void *s1, const void *s2)
+static bool
+compare_sccs (ddg_scc_ptr s1, ddg_scc_ptr s2)
 {
-  const int rec_l1 = (*(const ddg_scc_ptr *)s1)->recurrence_length;
-  const int rec_l2 = (*(const ddg_scc_ptr *)s2)->recurrence_length; 
-  return ((rec_l2 > rec_l1) - (rec_l2 < rec_l1));
+  const int rec_l1 = s1->recurrence_length;
+  const int rec_l2 = s2->recurrence_length;
+  return ((rec_l2 > rec_l1) < (rec_l2 < rec_l1));
 	  
 }
 
@@ -864,8 +866,7 @@
 static void
 order_sccs (ddg_all_sccs_ptr g)
 {
-  qsort (g->sccs, g->num_sccs, sizeof (ddg_scc_ptr),
-	 (int (*) (const void *, const void *)) compare_sccs);
+  std::sort (g->sccs, g->sccs + g->num_sccs, compare_sccs);
 }
 
 #ifdef ENABLE_CHECKING
Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c	(revisão 4)
+++ gcc/tree-ssa-sccvn.c	(cópia de trabalho)
@@ -46,6 +46,8 @@
 #include "tree-ssa-propagate.h"
 #include "tree-ssa-sccvn.h"
 
+#include <algorithm>
+
 /* This algorithm is based on the SCC algorithm presented by Keith
    Cooper and L. Taylor Simpson in "SCC-Based Value numbering"
    (http://citeseer.ist.psu.edu/41805.html).  In
@@ -2681,48 +2683,46 @@
 
 /* Compare two operands by reverse postorder index */
 
-static int
-compare_ops (const void *pa, const void *pb)
+static bool
+compare_ops (const tree& opa, const tree& opb)
 {
-  const tree opa = *((const tree *)pa);
-  const tree opb = *((const tree *)pb);
   gimple opstmta = SSA_NAME_DEF_STMT (opa);
   gimple opstmtb = SSA_NAME_DEF_STMT (opb);
   basic_block bba;
   basic_block bbb;
 
   if (gimple_nop_p (opstmta) && gimple_nop_p (opstmtb))
-    return SSA_NAME_VERSION (opa) - SSA_NAME_VERSION (opb);
+    return SSA_NAME_VERSION (opa) < SSA_NAME_VERSION (opb);
   else if (gimple_nop_p (opstmta))
-    return -1;
+    return true;
   else if (gimple_nop_p (opstmtb))
-    return 1;
+    return false;
 
   bba = gimple_bb (opstmta);
   bbb = gimple_bb (opstmtb);
 
   if (!bba && !bbb)
-    return SSA_NAME_VERSION (opa) - SSA_NAME_VERSION (opb);
+    return SSA_NAME_VERSION (opa) < SSA_NAME_VERSION (opb);
   else if (!bba)
-    return -1;
+    return true;
   else if (!bbb)
-    return 1;
+    return false;
 
   if (bba == bbb)
     {
       if (gimple_code (opstmta) == GIMPLE_PHI
 	  && gimple_code (opstmtb) == GIMPLE_PHI)
-	return SSA_NAME_VERSION (opa) - SSA_NAME_VERSION (opb);
+	return SSA_NAME_VERSION (opa) < SSA_NAME_VERSION (opb);
       else if (gimple_code (opstmta) == GIMPLE_PHI)
-	return -1;
+	return true;
       else if (gimple_code (opstmtb) == GIMPLE_PHI)
-	return 1;
+	return false;
       else if (gimple_uid (opstmta) != gimple_uid (opstmtb))
-        return gimple_uid (opstmta) - gimple_uid (opstmtb);
+        return gimple_uid (opstmta) < gimple_uid (opstmtb);
       else
-	return SSA_NAME_VERSION (opa) - SSA_NAME_VERSION (opb);
+	return SSA_NAME_VERSION (opa) < SSA_NAME_VERSION (opb);
     }
-  return rpo_numbers[bba->index] - rpo_numbers[bbb->index];
+  return rpo_numbers[bba->index] < rpo_numbers[bbb->index];
 }
 
 /* Sort an array containing members of a strongly connected component
@@ -2733,9 +2733,8 @@
 static void
 sort_scc (VEC (tree, heap) *scc)
 {
-  qsort (VEC_address (tree, scc),
-	 VEC_length (tree, scc),
-	 sizeof (tree),
+  std::sort (VEC_address (tree, scc),
+         VEC_address (tree, scc) + VEC_length (tree, scc),
 	 compare_ops);
 }
 
Index: gcc/cgraphunit.c
===================================================================
--- gcc/cgraphunit.c	(revisão 4)
+++ gcc/cgraphunit.c	(cópia de trabalho)
@@ -136,6 +136,8 @@
 #include "output.h"
 #include "coverage.h"
 
+#include <algorithm>
+
 static void cgraph_expand_all_functions (void);
 static void cgraph_mark_functions_to_output (void);
 static void cgraph_expand_function (struct cgraph_node *);
@@ -228,52 +230,44 @@
    "tree *" and point to static constructors.  DECL_INIT_PRIORITY is
    used to determine the sort order.  */
 
-static int
-compare_ctor (const void *p1, const void *p2)
+static bool
+compare_ctor (const tree& f1, const tree& f2)
 {
-  tree f1;
-  tree f2;
   int priority1;
   int priority2;
 
-  f1 = *(const tree *)p1;
-  f2 = *(const tree *)p2;
   priority1 = DECL_INIT_PRIORITY (f1);
   priority2 = DECL_INIT_PRIORITY (f2);
   
   if (priority1 < priority2)
-    return -1;
+    return true;
   else if (priority1 > priority2)
-    return 1;
+    return false;
   else
     /* Ensure a stable sort.  */
-    return (const tree *)p1 - (const tree *)p2;
+    return &f1 < &f2;
 }
 
 /* Comparison function for qsort.  P1 and P2 are actually of type
    "tree *" and point to static destructors.  DECL_FINI_PRIORITY is
    used to determine the sort order.  */
 
-static int
-compare_dtor (const void *p1, const void *p2)
+static bool
+compare_dtor (const tree& f1, const tree& f2)
 {
-  tree f1;
-  tree f2;
   int priority1;
   int priority2;
 
-  f1 = *(const tree *)p1;
-  f2 = *(const tree *)p2;
   priority1 = DECL_FINI_PRIORITY (f1);
   priority2 = DECL_FINI_PRIORITY (f2);
   
   if (priority1 < priority2)
-    return -1;
+    return true;
   else if (priority1 > priority2)
-    return 1;
+    return false;
   else
     /* Ensure a stable sort.  */
-    return (const tree *)p1 - (const tree *)p2;
+    return &f1 < &f2;
 }
 
 /* Generate functions to call static constructors and destructors
@@ -285,10 +279,10 @@
 {
   if (!VEC_empty (tree, static_ctors))
     {
+      size_t n = VEC_length (tree, static_ctors);
       gcc_assert (!targetm.have_ctors_dtors);
-      qsort (VEC_address (tree, static_ctors),
-	     VEC_length (tree, static_ctors), 
-	     sizeof (tree),
+      std::sort (VEC_address (tree, static_ctors),
+	     VEC_address (tree, static_ctors) + n,
 	     compare_ctor);
       build_cdtor (/*ctor_p=*/true,
 		   VEC_address (tree, static_ctors),
@@ -298,10 +292,10 @@
 
   if (!VEC_empty (tree, static_dtors))
     {
+      size_t n = VEC_length (tree, static_dtors);
       gcc_assert (!targetm.have_ctors_dtors);
-      qsort (VEC_address (tree, static_dtors),
-	     VEC_length (tree, static_dtors), 
-	     sizeof (tree),
+      std::sort (VEC_address (tree, static_dtors),
+	     VEC_address (tree, static_dtors) + n,
 	     compare_dtor);
       build_cdtor (/*ctor_p=*/false,
 		   VEC_address (tree, static_dtors),
Index: gcc/df-scan.c
===================================================================
--- gcc/df-scan.c	(revisão 4)
+++ gcc/df-scan.c	(cópia de trabalho)
@@ -46,6 +46,8 @@
 #include "df.h"
 #include "tree-pass.h"
 
+#include <algorithm>
+
 DEF_VEC_P(df_ref);
 DEF_VEC_ALLOC_P_STACK(df_ref);
 
@@ -153,8 +155,8 @@
 static void df_install_ref (df_ref, struct df_reg_info *, 
 			    struct df_ref_info *, bool);
 
-static int df_ref_compare (const void *, const void *);
-static int df_mw_compare (const void *, const void *);
+static bool df_ref_compare (df_ref ref1, df_ref ref2);
+static bool df_mw_compare (const df_mw_hardreg *mw1, const df_mw_hardreg *mw2);
 
 /* Indexed by hardware reg number, is true if that register is ever
    used in the current function.
@@ -809,7 +811,7 @@
       *ref_rec_ptr = ref_rec;
       ref_rec[count] = ref;
       ref_rec[count+1] = NULL;
-      qsort (ref_rec, count + 1, sizeof (df_ref), df_ref_compare);
+      std::sort (ref_rec, ref_rec + count + 1, df_ref_compare);
     }
   else
     {
@@ -2015,7 +2017,7 @@
 	      count++;
 	      ref_vec_t++;
 	    }
-	  qsort (ref_vec, count, sizeof (df_ref ), df_ref_compare);
+	  std::sort (ref_vec, ref_vec + count, df_ref_compare);
 
 	  the_ref = next_ref;
 	}
@@ -2204,8 +2206,9 @@
 		      VEC_address (df_mw_hardreg_ptr, collection_rec.mw_vec), 
 		      mw_len * sizeof (struct df_mw_hardreg *));
 	      insn_info->mw_hardregs[count + mw_len] = NULL;
-	      qsort (insn_info->mw_hardregs, count + mw_len, 
-		     sizeof (struct df_mw_hardreg *), df_mw_compare);
+	      std::sort (insn_info->mw_hardregs,
+		  insn_info->mw_hardregs + count + mw_len,
+		  df_mw_compare);
 	    }
 	  else
 	    {
@@ -2285,31 +2288,28 @@
    where all of the refs are of the same type, in the same insn, and
    have the same bb.  So these fields are not checked.  */
 
-static int
-df_ref_compare (const void *r1, const void *r2)
+static bool
+df_ref_compare (df_ref ref1, df_ref ref2)
 {
-  const df_ref ref1 = *(const df_ref *)r1;
-  const df_ref ref2 = *(const df_ref *)r2;
-
   if (ref1 == ref2)
     return 0;
 
   if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2))
-    return (int)DF_REF_CLASS (ref1) - (int)DF_REF_CLASS (ref2);
+    return (int)DF_REF_CLASS (ref1) < (int)DF_REF_CLASS (ref2);
 
   if (DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2))
-    return (int)DF_REF_REGNO (ref1) - (int)DF_REF_REGNO (ref2);
+    return (int)DF_REF_REGNO (ref1) < (int)DF_REF_REGNO (ref2);
   
   if (DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2))
-    return (int)DF_REF_TYPE (ref1) - (int)DF_REF_TYPE (ref2);
+    return (int)DF_REF_TYPE (ref1) < (int)DF_REF_TYPE (ref2);
 
   if (DF_REF_REG (ref1) != DF_REF_REG (ref2))
-    return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
+    return (int)DF_REF_ORDER (ref1) < (int)DF_REF_ORDER (ref2);
 
   /* Cannot look at the LOC field on artificial refs.  */
   if (DF_REF_CLASS (ref1) != DF_REF_ARTIFICIAL
       && DF_REF_LOC (ref1) != DF_REF_LOC (ref2))
-    return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
+    return (int)DF_REF_ORDER (ref1) < (int)DF_REF_ORDER (ref2);
 
   if (DF_REF_FLAGS (ref1) != DF_REF_FLAGS (ref2))
     {
@@ -2318,11 +2318,11 @@
 	 first.  */
       if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG) ==
 	  DF_REF_FLAGS_IS_SET (ref2, DF_REF_MW_HARDREG))
-	return DF_REF_FLAGS (ref1) - DF_REF_FLAGS (ref2);
+	return DF_REF_FLAGS (ref1) < DF_REF_FLAGS (ref2);
       else if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG))
-	return -1;
+	return true;
       else
-	return 1;
+	return false;
     }
 
   /* The classes are the same at this point so it is safe to only look
@@ -2365,7 +2365,8 @@
     {
       df_ref r0 = VEC_index (df_ref, *ref_vec, 0);
       df_ref r1 = VEC_index (df_ref, *ref_vec, 1);
-      if (df_ref_compare (&r0, &r1) > 0)
+      /* if (r0 > r1) ... */
+      if (df_ref_compare (r1, r0))
         df_swap_refs (ref_vec, 0, 1);
     }
   else
@@ -2374,7 +2375,8 @@
 	{
 	  df_ref r0 = VEC_index (df_ref, *ref_vec, i);
 	  df_ref r1 = VEC_index (df_ref, *ref_vec, i + 1);
-	  if (df_ref_compare (&r0, &r1) >= 0)
+	  /* if (r0 >= r1) ... */
+	  if (! df_ref_compare (r0, r1))
 	    break;
 	}
       /* If the array is already strictly ordered,
@@ -2386,7 +2388,8 @@
          of DF_REF_COMPARE.  */
       if (i == count - 1)
         return;
-      qsort (VEC_address (df_ref, *ref_vec), count, sizeof (df_ref),
+      std::sort (VEC_address (df_ref, *ref_vec),
+	  VEC_address (df_ref, *ref_vec) + count,
 	     df_ref_compare);
     }
 
@@ -2430,31 +2433,28 @@
 
 /* Compare MW1 and MW2 for sorting.  */
 
-static int
-df_mw_compare (const void *m1, const void *m2)
+static bool
+df_mw_compare (const df_mw_hardreg *mw1, const df_mw_hardreg *mw2)
 {
-  const struct df_mw_hardreg *const mw1 = *(const struct df_mw_hardreg *const*)m1;
-  const struct df_mw_hardreg *const mw2 = *(const struct df_mw_hardreg *const*)m2;
-
   if (mw1 == mw2)
-    return 0;
+    return false;
 
   if (mw1->type != mw2->type)
-    return mw1->type - mw2->type;
+    return mw1->type < mw2->type;
 
   if (mw1->flags != mw2->flags)
-    return mw1->flags - mw2->flags;
+    return mw1->flags < mw2->flags;
 
   if (mw1->start_regno != mw2->start_regno)
-    return mw1->start_regno - mw2->start_regno;
+    return mw1->start_regno < mw2->start_regno;
 
   if (mw1->end_regno != mw2->end_regno)
-    return mw1->end_regno - mw2->end_regno;
+    return mw1->end_regno < mw2->end_regno;
 
   if (mw1->mw_reg != mw2->mw_reg)
-    return mw1->mw_order - mw2->mw_order;
+    return mw1->mw_order < mw2->mw_order;
 
-  return 0;
+  return false;
 }
 
 
@@ -2476,7 +2476,8 @@
     {
       struct df_mw_hardreg *m0 = VEC_index (df_mw_hardreg_ptr, *mw_vec, 0);
       struct df_mw_hardreg *m1 = VEC_index (df_mw_hardreg_ptr, *mw_vec, 1);
-      if (df_mw_compare (&m0, &m1) > 0)
+      /* if (m0 > m1) ... */
+      if (df_mw_compare (m1, m0))
         {
           struct df_mw_hardreg *tmp = VEC_index (df_mw_hardreg_ptr,
 						 *mw_vec, 0);
@@ -2486,8 +2487,9 @@
         }
     }
   else
-    qsort (VEC_address (df_mw_hardreg_ptr, *mw_vec), count,
-	   sizeof (struct df_mw_hardreg *), df_mw_compare);
+    std::sort (VEC_address (df_mw_hardreg_ptr, *mw_vec),
+	VEC_address (df_mw_hardreg_ptr, *mw_vec) + count,
+	df_mw_compare);
 
   for (i=0; i<count-dist; i++)
     {
Index: gcc/cp/class.c
===================================================================
--- gcc/cp/class.c	(revisão 4)
+++ gcc/cp/class.c	(cópia de trabalho)
@@ -38,6 +38,8 @@
 #include "cgraph.h"
 #include "tree-dump.h"
 
+#include <algorithm>
+
 /* The number of nested classes being processed.  If we are not in the
    scope of any class, this is zero.  */
 
@@ -130,8 +132,8 @@
 static void determine_primary_bases (tree);
 static void finish_struct_methods (tree);
 static void maybe_warn_about_overly_private_class (tree);
-static int method_name_cmp (const void *, const void *);
-static int resort_method_name_cmp (const void *, const void *);
+static bool method_name_cmp (const tree&, const tree&);
+static bool resort_method_name_cmp (const tree&, const tree&);
 static void add_implicitly_declared_members (tree, int, int);
 static tree fixed_type_or_null (tree, int *, int *);
 static tree build_simple_base_path (tree expr, tree binfo);
@@ -1698,48 +1700,43 @@
   void *cookie;
 } resort_data;
 
-/* Comparison function to compare two TYPE_METHOD_VEC entries by name.  */
+/* Strict weak ordering of TYPE_METHOD_VEC entries by name.  */
 
-static int
-method_name_cmp (const void* m1_p, const void* m2_p)
+static bool
+method_name_cmp (const tree& m1, const tree& m2)
 {
-  const tree *const m1 = (const tree *) m1_p;
-  const tree *const m2 = (const tree *) m2_p;
-
-  if (*m1 == NULL_TREE && *m2 == NULL_TREE)
-    return 0;
-  if (*m1 == NULL_TREE)
-    return -1;
-  if (*m2 == NULL_TREE)
-    return 1;
-  if (DECL_NAME (OVL_CURRENT (*m1)) < DECL_NAME (OVL_CURRENT (*m2)))
-    return -1;
-  return 1;
+  if (m1 == NULL_TREE && m2 == NULL_TREE)
+    return false;
+  if (m1 == NULL_TREE)
+    return true;
+  if (m2 == NULL_TREE)
+    return false;
+  if (DECL_NAME (OVL_CURRENT (m1)) < DECL_NAME (OVL_CURRENT (m2)))
+    return true;
+  return false;
 }
 
-/* This routine compares two fields like method_name_cmp but using the
+/* Strict weak ordering of fields like method_name_less but using the
    pointer operator in resort_field_decl_data.  */
 
-static int
-resort_method_name_cmp (const void* m1_p, const void* m2_p)
+static bool
+resort_method_name_cmp (const tree& m1, const tree& m2)
 {
-  const tree *const m1 = (const tree *) m1_p;
-  const tree *const m2 = (const tree *) m2_p;
-  if (*m1 == NULL_TREE && *m2 == NULL_TREE)
-    return 0;
-  if (*m1 == NULL_TREE)
-    return -1;
-  if (*m2 == NULL_TREE)
-    return 1;
+  if (m1 == NULL_TREE && m2 == NULL_TREE)
+    return false;
+  if (m1 == NULL_TREE)
+    return true;
+  if (m2 == NULL_TREE)
+    return false;
   {
-    tree d1 = DECL_NAME (OVL_CURRENT (*m1));
-    tree d2 = DECL_NAME (OVL_CURRENT (*m2));
+    tree d1 = DECL_NAME (OVL_CURRENT (m1));
+    tree d2 = DECL_NAME (OVL_CURRENT (m2));
     resort_data.new_value (&d1, resort_data.cookie);
     resort_data.new_value (&d2, resort_data.cookie);
     if (d1 < d2)
-      return -1;
+      return true;
   }
-  return 1;
+  return false;
 }
 
 /* Resort TYPE_METHOD_VEC because pointers have been reordered.  */
@@ -1767,8 +1764,8 @@
     {
       resort_data.new_value = new_value;
       resort_data.cookie = cookie;
-      qsort (VEC_address (tree, method_vec) + slot, len - slot, sizeof (tree),
-	     resort_method_name_cmp);
+      std::sort (VEC_address (tree, method_vec) + slot,
+	     VEC_address (tree, method_vec) + len, resort_method_name_cmp);
     }
 }
 
@@ -1808,8 +1805,8 @@
     if (!DECL_CONV_FN_P (OVL_CURRENT (fn_fields)))
       break;
   if (len - slot > 1)
-    qsort (VEC_address (tree, method_vec) + slot,
-	   len-slot, sizeof (tree), method_name_cmp);
+    std::sort (VEC_address (tree, method_vec) + slot,
+	   VEC_address (tree, method_vec) + len, method_name_cmp);
 }
 
 /* Make BINFO's vtable have N entries, including RTTI entries,
@@ -5372,8 +5369,7 @@
 	  sizeof (struct sorted_fields_type) + n_fields * sizeof (tree));
       field_vec->len = n_fields;
       add_fields_to_record_type (TYPE_FIELDS (t), field_vec, 0);
-      qsort (field_vec->elts, n_fields, sizeof (tree),
-	     field_decl_cmp);
+      std::sort (field_vec->elts, field_vec->elts + n_fields, field_decl_cmp);
       CLASSTYPE_SORTED_FIELDS (t) = field_vec;
     }
 
Index: gcc/haifa-sched.c
===================================================================
--- gcc/haifa-sched.c	(revisão 4)
+++ gcc/haifa-sched.c	(cópia de trabalho)
@@ -148,6 +148,8 @@
 #include "dbgcnt.h"
 #include "cfgloop.h"
 
+#include <algorithm>
+
 #ifdef INSN_SCHEDULING
 
 /* issue_rate is the number of insns that can be scheduled in the same
@@ -503,7 +505,6 @@
 /* Forward declarations.  */
 
 static int priority (rtx);
-static int rank_for_schedule (const void *, const void *);
 static void swap_sort (rtx *, int);
 static void queue_insn (rtx, int);
 static int schedule_insn (rtx);
@@ -874,25 +875,23 @@
 do { if ((N_READY) == 2)				             \
        swap_sort (READY, N_READY);			             \
      else if ((N_READY) > 2)                                         \
-         qsort (READY, N_READY, sizeof (rtx), rank_for_schedule); }  \
+         std::sort (READY, READY + N_READY, rank_for_schedule); }  \
 while (0)
 
 /* Returns a positive value if x is preferred; returns a negative value if
    y is preferred.  Should never return 0, since that will make the sort
    unstable.  */
 
-static int
-rank_for_schedule (const void *x, const void *y)
+static bool
+rank_for_schedule (rtx tmp, rtx tmp2)
 {
-  rtx tmp = *(const rtx *) y;
-  rtx tmp2 = *(const rtx *) x;
   int tmp_class, tmp2_class;
   int val, priority_val, weight_val, info_val;
 
   /* The insn in a schedule group should be issued the first.  */
   if (flag_sched_group_heuristic && 
       SCHED_GROUP_P (tmp) != SCHED_GROUP_P (tmp2))
-    return SCHED_GROUP_P (tmp2) ? 1 : -1;
+    return ! SCHED_GROUP_P (tmp2);
 
   /* Make sure that priority of TMP and TMP2 are initialized.  */
   gcc_assert (INSN_PRIORITY_KNOWN (tmp) && INSN_PRIORITY_KNOWN (tmp2));
@@ -901,7 +900,7 @@
   priority_val = INSN_PRIORITY (tmp2) - INSN_PRIORITY (tmp);
 
   if (flag_sched_critical_path_heuristic && priority_val)
-    return priority_val;
+    return priority_val < 0;
 
   /* Prefer speculative insn with greater dependencies weakness.  */
   if (flag_sched_spec_insn_heuristic && spec_info)
@@ -924,17 +923,17 @@
 
       dw = dw2 - dw1;
       if (dw > (NO_DEP_WEAK / 8) || dw < -(NO_DEP_WEAK / 8))
-	return dw;
+	return dw < 0;
     }
 
   /* Prefer an insn with smaller contribution to registers-pressure.  */
   if (flag_sched_reg_pressure_heuristic && !reload_completed &&
       (weight_val = INSN_REG_WEIGHT (tmp) - INSN_REG_WEIGHT (tmp2)))
-    return weight_val;
+    return weight_val < 0;
 
   info_val = (*current_sched_info->rank) (tmp, tmp2);
   if(flag_sched_rank_heuristic && info_val)
-    return info_val;
+    return info_val < 0;
 
   /* Compare insns based on their relation to the last-scheduled-insn.  */
   if (flag_sched_last_insn_heuristic && INSN_P (last_scheduled_insn))
@@ -968,7 +967,7 @@
 	tmp2_class = 2;
 
       if ((val = tmp2_class - tmp_class))
-	return val;
+	return val < 0;
     }
 
   /* Prefer the insn which has more later insns that depend on it.
@@ -979,12 +978,12 @@
 	 - sd_lists_size (tmp, SD_LIST_FORW));
 
   if (flag_sched_dep_count_heuristic && val != 0)
-    return val;
+    return val < 0;
 
   /* If insns are equally good, sort by INSN_LUID (original insn order),
      so that we make the sort stable.  This minimizes instruction movement,
      thus minimizing sched's effect on debugging and cross-jumping.  */
-  return INSN_LUID (tmp) - INSN_LUID (tmp2);
+  return INSN_LUID (tmp) < INSN_LUID (tmp2);
 }
 
 /* Resort the array A in which only element at index N may be out of order.  */
@@ -995,7 +994,7 @@
   rtx insn = a[n - 1];
   int i = n - 2;
 
-  while (i >= 0 && rank_for_schedule (a + i, &insn) >= 0)
+  while (i >= 0 && ! rank_for_schedule (a[i], insn))
     {
       a[i + 1] = a[i];
       i -= 1;
Index: gcc/caller-save.c
===================================================================
--- gcc/caller-save.c	(revisão 4)
+++ gcc/caller-save.c	(cópia de trabalho)
@@ -40,6 +40,8 @@
 #include "df.h"
 #include "ggc.h"
 
+#include <algorithm>
+
 /* Call used hard registers which can not be saved because there is no
    insn for this.  */
 HARD_REG_SET no_caller_save_reg_set;
@@ -105,7 +107,6 @@
 static void initiate_saved_hard_regs (void);
 static struct saved_hard_reg *new_saved_hard_reg (int, int);
 static void finish_saved_hard_regs (void);
-static int saved_hard_reg_compare_func (const void *, const void *);
 
 static void mark_set_regs (rtx, const_rtx, void *);
 static void add_stored_regs (rtx, const_rtx, void *);
@@ -387,20 +388,17 @@
 /* The function is used to sort the saved hard register structures
    according their frequency.  */
 static int
-saved_hard_reg_compare_func (const void *v1p, const void *v2p)
+saved_hard_reg_compare_func (saved_hard_reg* p1, saved_hard_reg* p2)
 {
-  const struct saved_hard_reg *p1 = *(struct saved_hard_reg * const *) v1p;
-  const struct saved_hard_reg *p2 = *(struct saved_hard_reg * const *) v2p;
-  
   if (flag_omit_frame_pointer)
     {
       if (p1->call_freq - p2->call_freq != 0)
-	return p1->call_freq - p2->call_freq;
+	return p1->call_freq < p2->call_freq;
     }
   else if (p2->call_freq - p1->call_freq != 0)
-    return p2->call_freq - p1->call_freq;
+    return p2->call_freq < p1->call_freq;
 
-  return p1->num - p2->num;
+  return p1->num < p2->num;
 }
 
 /* Allocate save areas for any hard registers that might need saving.
@@ -590,7 +588,7 @@
 	    }
 	}
       /* Sort saved hard regs.  */
-      qsort (all_saved_regs, saved_regs_num, sizeof (struct saved_hard_reg *),
+      std::sort (all_saved_regs, all_saved_regs + saved_regs_num,
 	     saved_hard_reg_compare_func);
       /* Initiate slots available from the previous reload
 	 iteration.  */
Index: gcc/ira-color.c
===================================================================
--- gcc/ira-color.c	(revisão 4)
+++ gcc/ira-color.c	(cópia de trabalho)
@@ -40,6 +40,8 @@
 #include "splay-tree.h"
 #include "ira-int.h"
 
+#include <algorithm>
+
 /* This file contains code for regional graph coloring, spill/restore
    code placement optimization, and code helping the reload pass to do
    a better job.  */
@@ -396,21 +398,19 @@
 
 /* Sort allocnos according to the profit of usage of a hard register
    instead of memory for them. */
-static int
-allocno_cost_compare_func (const void *v1p, const void *v2p)
+static bool
+allocno_cost_compare_func (ira_allocno_t p1, ira_allocno_t p2)
 {
-  ira_allocno_t p1 = *(const ira_allocno_t *) v1p;
-  ira_allocno_t p2 = *(const ira_allocno_t *) v2p;
   int c1, c2;
 
   c1 = ALLOCNO_UPDATED_MEMORY_COST (p1) - ALLOCNO_UPDATED_COVER_CLASS_COST (p1);
   c2 = ALLOCNO_UPDATED_MEMORY_COST (p2) - ALLOCNO_UPDATED_COVER_CLASS_COST (p2);
   if (c1 - c2)
-    return c1 - c2;
+    return c1 < c2;
 
   /* If regs are equally good, sort by allocno numbers, so that the
      results of qsort leave nothing to chance.  */
-  return ALLOCNO_NUM (p1) - ALLOCNO_NUM (p2);
+  return ALLOCNO_NUM (p1) < ALLOCNO_NUM (p2);
 }
 
 /* Print all allocnos coalesced with ALLOCNO.  */
@@ -627,7 +627,7 @@
 	  if (a == allocno)
 	    break;
 	}
-      qsort (sorted_allocnos, j, sizeof (ira_allocno_t), 
+      std::sort (sorted_allocnos, sorted_allocnos + j,
 	     allocno_cost_compare_func);
       for (i = 0; i < j; i++)
 	{
@@ -736,22 +736,20 @@
    hard register will be assigned to it after assignment to the second
    one.  As the result of such assignment order, the second allocno
    has a better chance to get the best hard register.  */
-static int
-bucket_allocno_compare_func (const void *v1p, const void *v2p)
+static bool
+bucket_allocno_compare_func (ira_allocno_t a1, ira_allocno_t a2)
 {
-  ira_allocno_t a1 = *(const ira_allocno_t *) v1p;
-  ira_allocno_t a2 = *(const ira_allocno_t *) v2p;
   int diff, a1_freq, a2_freq, a1_num, a2_num;
 
   if ((diff = (int) ALLOCNO_COVER_CLASS (a2) - ALLOCNO_COVER_CLASS (a1)) != 0)
-    return diff;
+    return diff < 0;
   get_coalesced_allocnos_attributes (a1, &a1_freq, &a1_num);
   get_coalesced_allocnos_attributes (a2, &a2_freq, &a2_num);
   if ((diff = a2_num - a1_num) != 0)
-    return diff;
+    return diff < 0;
   else if ((diff = a1_freq - a2_freq) != 0)
-    return diff;
-  return ALLOCNO_NUM (a2) - ALLOCNO_NUM (a1);
+    return diff < 0;
+  return ALLOCNO_NUM (a2) < ALLOCNO_NUM (a1);
 }
 
 /* Sort bucket *BUCKET_PTR and return the result through
@@ -766,7 +764,7 @@
     sorted_allocnos[n++] = a;
   if (n <= 1)
     return;
-  qsort (sorted_allocnos, n, sizeof (ira_allocno_t),
+  std::sort (sorted_allocnos, sorted_allocnos + n,
 	 bucket_allocno_compare_func);
   head = NULL;
   for (n--; n >= 0; n--)
@@ -800,7 +798,7 @@
   for (before = *bucket_ptr, after = NULL;
        before != NULL;
        after = before, before = ALLOCNO_NEXT_BUCKET_ALLOCNO (before))
-    if (bucket_allocno_compare_func (&allocno, &before) < 0)
+    if (bucket_allocno_compare_func (allocno, before))
       break;
   ALLOCNO_NEXT_BUCKET_ALLOCNO (allocno) = before;
   ALLOCNO_PREV_BUCKET_ALLOCNO (allocno) = after;
@@ -1496,20 +1494,19 @@
 
 /* The function is used to sort allocnos according to their execution
    frequencies.  */
-static int
-copy_freq_compare_func (const void *v1p, const void *v2p)
+static bool
+copy_freq_compare_func (ira_copy_t cp1, ira_copy_t cp2)
 {
-  ira_copy_t cp1 = *(const ira_copy_t *) v1p, cp2 = *(const ira_copy_t *) v2p;
   int pri1, pri2;
 
   pri1 = cp1->freq;
   pri2 = cp2->freq;
   if (pri2 - pri1)
-    return pri2 - pri1;
+    return pri2 < pri1;
 
   /* If freqencies are equal, sort by copies, so that the results of
      qsort leave nothing to chance.  */
-  return cp1->num - cp2->num;
+  return cp1->num < cp2->num;
 }
 
 /* Merge two sets of coalesced allocnos given correspondingly by
@@ -1652,7 +1649,7 @@
 	    gcc_unreachable ();
 	}
     }
-  qsort (sorted_copies, cp_num, sizeof (ira_copy_t), copy_freq_compare_func);
+  std::sort (sorted_copies, sorted_copies + cp_num, copy_freq_compare_func);
   /* Coalesced copies, most frequently executed first.  */
   for (; cp_num != 0;)
     {
@@ -1730,21 +1727,19 @@
 
 /* Sort allocnos according to their priorities which are calculated
    analogous to ones in file `global.c'.  */
-static int
-allocno_priority_compare_func (const void *v1p, const void *v2p)
+static bool
+allocno_priority_compare_func (ira_allocno_t a1, ira_allocno_t a2)
 {
-  ira_allocno_t a1 = *(const ira_allocno_t *) v1p;
-  ira_allocno_t a2 = *(const ira_allocno_t *) v2p;
   int pri1, pri2;
 
   pri1 = allocno_priorities[ALLOCNO_NUM (a1)];
   pri2 = allocno_priorities[ALLOCNO_NUM (a2)];
   if (pri2 - pri1)
-    return pri2 - pri1;
+    return pri2 < pri1;
 
   /* If regs are equally good, sort by allocnos, so that the results of
      qsort leave nothing to chance.  */
-  return ALLOCNO_NUM (a1) - ALLOCNO_NUM (a2);
+  return ALLOCNO_NUM (a1) < ALLOCNO_NUM (a2);
 }
 
 /* Chaitin-Briggs coloring for allocnos in COLORING_ALLOCNO_BITMAP
@@ -1785,7 +1780,7 @@
       if (n != 0)
 	{
 	  setup_allocno_priorities (sorted_allocnos, n);
-	  qsort (sorted_allocnos, n, sizeof (ira_allocno_t),
+	  std::sort (sorted_allocnos, sorted_allocnos + n,
 		 allocno_priority_compare_func);
 	  for (i = 0; i < n; i++)
 	    {
@@ -2314,7 +2309,7 @@
   if (allocnos_to_color_num > 1)
     {
       setup_allocno_priorities (sorted_allocnos, allocnos_to_color_num);
-      qsort (sorted_allocnos, allocnos_to_color_num, sizeof (ira_allocno_t),
+      std::sort (sorted_allocnos, sorted_allocnos + allocnos_to_color_num,
 	     allocno_priority_compare_func);
     }
   for (i = 0; i < allocnos_to_color_num; i++)
@@ -2356,20 +2351,18 @@
 /* Sort pseudos according frequencies of coalesced allocno sets they
    belong to (putting most frequently ones first), and according to
    coalesced allocno set order numbers.  */
-static int
-coalesced_pseudo_reg_freq_compare (const void *v1p, const void *v2p)
+static bool
+coalesced_pseudo_reg_freq_compare (int regno1, int regno2)
 {
-  const int regno1 = *(const int *) v1p;
-  const int regno2 = *(const int *) v2p;
   int diff;
 
   if ((diff = (regno_coalesced_allocno_cost[regno2]
 	       - regno_coalesced_allocno_cost[regno1])) != 0)
-    return diff;
+    return diff < 0;
   if ((diff = (regno_coalesced_allocno_num[regno1]
 	       - regno_coalesced_allocno_num[regno2])) != 0)
-    return diff;
-  return regno1 - regno2;
+    return diff < 0;
+  return regno1 < regno2;
 }
 
 /* Widest width in which each pseudo reg is referred to (via subreg).
@@ -2387,11 +2380,9 @@
 /* Sort pseudos according their slot numbers (putting ones with
   smaller numbers first, or last when the frame pointer is not
   needed).  */
-static int
-coalesced_pseudo_reg_slot_compare (const void *v1p, const void *v2p)
+static bool
+coalesced_pseudo_reg_slot_compare (int regno1, int regno2)
 {
-  const int regno1 = *(const int *) v1p;
-  const int regno2 = *(const int *) v2p;
   ira_allocno_t a1 = ira_regno_allocno_map[regno1];
   ira_allocno_t a2 = ira_regno_allocno_map[regno2];
   int diff, slot_num1, slot_num2;
@@ -2400,21 +2391,24 @@
   if (a1 == NULL || ALLOCNO_HARD_REGNO (a1) >= 0)
     {
       if (a2 == NULL || ALLOCNO_HARD_REGNO (a2) >= 0)
-	return regno1 - regno2;
-      return 1;
+	return regno1 < regno2;
+      return false;
     }
   else if (a2 == NULL || ALLOCNO_HARD_REGNO (a2) >= 0)
-    return -1;
+    return true;
   slot_num1 = -ALLOCNO_HARD_REGNO (a1);
   slot_num2 = -ALLOCNO_HARD_REGNO (a2);
   if ((diff = slot_num1 - slot_num2) != 0)
-    return (frame_pointer_needed
-	    || !FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD ? diff : -diff);
+    if (frame_pointer_needed
+	    || !FRAME_GROWS_DOWNWARD == STACK_GROWS_DOWNWARD)
+      return diff < 0;
+    else
+      return diff > 0;
   total_size1 = MAX (PSEUDO_REGNO_BYTES (regno1), regno_max_ref_width[regno1]);
   total_size2 = MAX (PSEUDO_REGNO_BYTES (regno2), regno_max_ref_width[regno2]);
   if ((diff = total_size2 - total_size1) != 0)
-    return diff;
-  return regno1 - regno2;
+    return diff < 0;
+  return regno1 < regno2;
 }
 
 /* Setup REGNO_COALESCED_ALLOCNO_COST and REGNO_COALESCED_ALLOCNO_NUM
@@ -2636,7 +2630,7 @@
   setup_coalesced_allocno_costs_and_nums (pseudo_regnos, n);
   /* Sort regnos according frequencies of the corresponding coalesced
      allocno sets.  */
-  qsort (pseudo_regnos, n, sizeof (int), coalesced_pseudo_reg_freq_compare);
+  std::sort (pseudo_regnos, pseudo_regnos + n, coalesced_pseudo_reg_freq_compare);
   spilled_coalesced_allocnos
     = (ira_allocno_t *) ira_allocate (ira_allocnos_num
 				      * sizeof (ira_allocno_t));
@@ -2648,7 +2642,7 @@
       && coalesce_spill_slots (spilled_coalesced_allocnos, num))
     {
       setup_coalesced_allocno_costs_and_nums (pseudo_regnos, n);
-      qsort (pseudo_regnos, n, sizeof (int),
+      std::sort (pseudo_regnos, pseudo_regnos + n,
 	     coalesced_pseudo_reg_freq_compare);
       num = collect_spilled_coalesced_allocnos (pseudo_regnos, n,
 						spilled_coalesced_allocnos);
@@ -2693,7 +2687,7 @@
   ira_free (spilled_coalesced_allocnos);
   /* Sort regnos according the slot numbers.  */
   regno_max_ref_width = reg_max_ref_width;
-  qsort (pseudo_regnos, n, sizeof (int), coalesced_pseudo_reg_slot_compare);
+  std::sort (pseudo_regnos, pseudo_regnos + n, coalesced_pseudo_reg_slot_compare);
   /* Uncoalesce allocnos which is necessary for (re)assigning during
      the reload pass.  */
   FOR_EACH_ALLOCNO (a, ai)
@@ -2831,16 +2825,14 @@
 
 /* Sort pseudos according their usage frequencies (putting most
    frequently ones first).  */
-static int
-pseudo_reg_compare (const void *v1p, const void *v2p)
+static bool
+pseudo_reg_compare (int regno1, int regno2)
 {
-  int regno1 = *(const int *) v1p;
-  int regno2 = *(const int *) v2p;
   int diff;
 
   if ((diff = REG_FREQ (regno2) - REG_FREQ (regno1)) != 0)
-    return diff;
-  return regno1 - regno2;
+    return diff < 0;
+  return regno1 < regno2;
 }
 
 /* Try to allocate hard registers to SPILLED_PSEUDO_REGS (there are
@@ -2864,7 +2856,7 @@
   ira_allocno_conflict_iterator aci;
 
   if (num > 1)
-    qsort (spilled_pseudo_regs, num, sizeof (int), pseudo_reg_compare);
+    std::sort (spilled_pseudo_regs, spilled_pseudo_regs + num, pseudo_reg_compare);
   changed_p = false;
   /* Try to assign hard registers to pseudos from
      SPILLED_PSEUDO_REGS.  */
@@ -2921,7 +2913,7 @@
   if (n != 0)
     {
       setup_allocno_priorities (sorted_allocnos, n);
-      qsort (sorted_allocnos, n, sizeof (ira_allocno_t),
+      std::sort (sorted_allocnos, sorted_allocnos + n,
 	     allocno_priority_compare_func);
       for (i = 0; i < n; i++)
 	{
@@ -3273,7 +3265,7 @@
 						  * ira_max_point);
   for (i = 0; i < ira_max_point; i++)
     CLEAR_HARD_REG_SET (used_hard_regs[i]);
-  qsort (sorted_allocnos, num, sizeof (ira_allocno_t),
+  std::sort (sorted_allocnos, sorted_allocnos + num,
 	 allocno_priority_compare_func);
   for (i = 0; i < num; i++)
     {
Index: gcc/sel-sched.c
===================================================================
--- gcc/sel-sched.c	(revisão 4)
+++ gcc/sel-sched.c	(cópia de trabalho)
@@ -46,6 +46,8 @@
 #include "rtlhooks-def.h"
 #include "output.h"
 
+#include <algorithm>
+
 #ifdef INSN_SCHEDULING
 #include "sel-sched-ir.h"
 #include "sel-sched-dump.h"
@@ -555,7 +557,6 @@
 
 /* Forward declarations of static functions.  */
 static bool rtx_ok_for_substitution_p (rtx, rtx);
-static int sel_rank_for_schedule (const void *, const void *);
 static av_set_t find_sequential_best_exprs (bnd_t, expr_t, bool);
 
 static rtx get_dest_from_orig_ops (av_set_t);
@@ -3247,66 +3248,64 @@
 }
 
 /* Rank two available exprs for schedule.  Never return 0 here.  */
-static int 
-sel_rank_for_schedule (const void *x, const void *y)
+static bool
+sel_rank_for_schedule (expr_t x, expr_t y)
 {
-  expr_t tmp = *(const expr_t *) y;
-  expr_t tmp2 = *(const expr_t *) x;
   insn_t tmp_insn, tmp2_insn;
   vinsn_t tmp_vinsn, tmp2_vinsn;
   int val;
 
-  tmp_vinsn = EXPR_VINSN (tmp);
-  tmp2_vinsn = EXPR_VINSN (tmp2);
-  tmp_insn = EXPR_INSN_RTX (tmp);
-  tmp2_insn = EXPR_INSN_RTX (tmp2);
+  tmp_vinsn = EXPR_VINSN (x);
+  tmp2_vinsn = EXPR_VINSN (y);
+  tmp_insn = EXPR_INSN_RTX (x);
+  tmp2_insn = EXPR_INSN_RTX (y);
   
   /* Prefer SCHED_GROUP_P insns to any others.  */
   if (SCHED_GROUP_P (tmp_insn) != SCHED_GROUP_P (tmp2_insn))
     {
       if (VINSN_UNIQUE_P (tmp_vinsn) && VINSN_UNIQUE_P (tmp2_vinsn)) 
-        return SCHED_GROUP_P (tmp2_insn) ? 1 : -1;
+        return ! SCHED_GROUP_P (tmp2_insn);
 
       /* Now uniqueness means SCHED_GROUP_P is set, because schedule groups
          cannot be cloned.  */
       if (VINSN_UNIQUE_P (tmp2_vinsn))
-        return 1;
-      return -1;
+        return false;
+      return true;
     }
 
   /* Discourage scheduling of speculative checks.  */
   val = (sel_insn_is_speculation_check (tmp_insn)
 	 - sel_insn_is_speculation_check (tmp2_insn));
   if (val)
-    return val;
+    return val < 0;
 
   /* Prefer not scheduled insn over scheduled one.  */
-  if (EXPR_SCHED_TIMES (tmp) > 0 || EXPR_SCHED_TIMES (tmp2) > 0)
+  if (EXPR_SCHED_TIMES (x) > 0 || EXPR_SCHED_TIMES (y) > 0)
     {
-      val = EXPR_SCHED_TIMES (tmp) - EXPR_SCHED_TIMES (tmp2);
+      val = EXPR_SCHED_TIMES (x) - EXPR_SCHED_TIMES (y);
       if (val)
-	return val;
+	return val < 0;
     }
 
   /* Prefer jump over non-jump instruction.  */
   if (control_flow_insn_p (tmp_insn) && !control_flow_insn_p (tmp2_insn))
-    return -1;
+    return true;
   else if (control_flow_insn_p (tmp2_insn) && !control_flow_insn_p (tmp_insn))
-    return 1;
+    return false;
 
   /* Prefer an expr with greater priority.  */
-  if (EXPR_USEFULNESS (tmp) != 0 && EXPR_USEFULNESS (tmp2) != 0)
+  if (EXPR_USEFULNESS (x) != 0 && EXPR_USEFULNESS (y) != 0)
     {
-      int p2 = EXPR_PRIORITY (tmp2) + EXPR_PRIORITY_ADJ (tmp2),
-          p1 = EXPR_PRIORITY (tmp) + EXPR_PRIORITY_ADJ (tmp);
+      int p2 = EXPR_PRIORITY (y) + EXPR_PRIORITY_ADJ (y),
+          p1 = EXPR_PRIORITY (x) + EXPR_PRIORITY_ADJ (x);
 
-      val = p2 * EXPR_USEFULNESS (tmp2) - p1 * EXPR_USEFULNESS (tmp);
+      val = p2 * EXPR_USEFULNESS (y) - p1 * EXPR_USEFULNESS (x);
     }
   else
-    val = EXPR_PRIORITY (tmp2) - EXPR_PRIORITY (tmp) 
-	  + EXPR_PRIORITY_ADJ (tmp2) - EXPR_PRIORITY_ADJ (tmp);
+    val = EXPR_PRIORITY (y) - EXPR_PRIORITY (x) 
+	  + EXPR_PRIORITY_ADJ (y) - EXPR_PRIORITY_ADJ (x);
   if (val)
-    return val;
+    return val < 0;
 
   if (spec_info != NULL && spec_info->mask != 0)
     /* This code was taken from haifa-sched.c: rank_for_schedule ().  */
@@ -3315,13 +3314,13 @@
       dw_t dw1, dw2;
       int dw;
 
-      ds1 = EXPR_SPEC_DONE_DS (tmp);
+      ds1 = EXPR_SPEC_DONE_DS (x);
       if (ds1)
 	dw1 = ds_weak (ds1);
       else
 	dw1 = NO_DEP_WEAK;
 
-      ds2 = EXPR_SPEC_DONE_DS (tmp2);
+      ds2 = EXPR_SPEC_DONE_DS (y);
       if (ds2)
 	dw2 = ds_weak (ds2);
       else
@@ -3329,24 +3328,24 @@
 
       dw = dw2 - dw1;
       if (dw > (NO_DEP_WEAK / 8) || dw < -(NO_DEP_WEAK / 8))
-	return dw;
+	return dw < 0;
     }
 
-  tmp_insn = EXPR_INSN_RTX (tmp);
-  tmp2_insn = EXPR_INSN_RTX (tmp2);
+  tmp_insn = EXPR_INSN_RTX (x);
+  tmp2_insn = EXPR_INSN_RTX (y);
 
   /* Prefer an old insn to a bookkeeping insn.  */
   if (INSN_UID (tmp_insn) < first_emitted_uid 
       && INSN_UID (tmp2_insn) >= first_emitted_uid)
-    return -1;
+    return true;
   if (INSN_UID (tmp_insn) >= first_emitted_uid 
       && INSN_UID (tmp2_insn) < first_emitted_uid)
-    return 1;
+    return false;
 
   /* Prefer an insn with smaller UID, as a last resort.  
      We can't safely use INSN_LUID as it is defined only for those insns
      that are in the stream.  */
-  return INSN_UID (tmp_insn) - INSN_UID (tmp2_insn);
+  return INSN_UID (tmp_insn) < INSN_UID (tmp2_insn);
 }
 
 /* Filter out expressions from av set pointed to by AV_PTR 
@@ -3647,8 +3646,9 @@
     }
 
   /* Sort the vector.  */
-  qsort (VEC_address (expr_t, vec_av_set), VEC_length (expr_t, vec_av_set),
-         sizeof (expr_t), sel_rank_for_schedule);
+  std::sort (VEC_address (expr_t, vec_av_set),
+      VEC_address (expr_t, vec_av_set) + VEC_length (expr_t, vec_av_set),
+      sel_rank_for_schedule);
 
   /* We record maximal priority of insns in av set for current instruction
      group.  */
@@ -3862,8 +3862,9 @@
     gcc_assert (min_need_stall == 0);
 
   /* Sort the vector.  */
-  qsort (VEC_address (expr_t, vec_av_set), VEC_length (expr_t, vec_av_set),
-         sizeof (expr_t), sel_rank_for_schedule);
+  std::sort (VEC_address (expr_t, vec_av_set),
+      VEC_address (expr_t, vec_av_set) + VEC_length (expr_t, vec_av_set),
+      sel_rank_for_schedule);
   
   if (sched_verbose >= 4)
     {
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c	(revisão 4)
+++ gcc/dwarf2out.c	(cópia de trabalho)
@@ -90,6 +90,8 @@
 #include "cgraph.h"
 #include "input.h"
 
+#include <algorithm>
+
 #ifdef DWARF2_DEBUGGING_INFO
 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
 
@@ -5925,7 +5927,6 @@
 static void retry_incomplete_types (void);
 static void gen_type_die_for_member (tree, tree, dw_die_ref);
 static void splice_child_die (dw_die_ref, dw_die_ref);
-static int file_info_cmp (const void *, const void *);
 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
 				     const char *, const char *, unsigned);
 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
@@ -9418,11 +9419,9 @@
 /* Callback function for file_info comparison.  We sort by looking at
    the directories in the path.  */
 
-static int
-file_info_cmp (const void *p1, const void *p2)
+static bool
+file_info_cmp (const file_info& s1, const file_info& s2)
 {
-  const struct file_info *const s1 = (const struct file_info *) p1;
-  const struct file_info *const s2 = (const struct file_info *) p2;
   const unsigned char *cp1;
   const unsigned char *cp2;
 
@@ -9431,25 +9430,25 @@
      we return the same value when identical operands are passed in opposite
      orders.  So if neither has a directory, return 0 and otherwise return
      1 or -1 depending on which one has the directory.  */
-  if ((s1->path == s1->fname || s2->path == s2->fname))
-    return (s2->path == s2->fname) - (s1->path == s1->fname);
+  if ((s1.path == s1.fname || s2.path == s2.fname))
+    return (s2.path == s2.fname) < (s1.path == s1.fname);
 
-  cp1 = (const unsigned char *) s1->path;
-  cp2 = (const unsigned char *) s2->path;
+  cp1 = (const unsigned char *) s1.path;
+  cp2 = (const unsigned char *) s2.path;
 
   while (1)
     {
       ++cp1;
       ++cp2;
       /* Reached the end of the first path?  If so, handle like above.  */
-      if ((cp1 == (const unsigned char *) s1->fname)
-	  || (cp2 == (const unsigned char *) s2->fname))
-	return ((cp2 == (const unsigned char *) s2->fname)
-		- (cp1 == (const unsigned char *) s1->fname));
+      if ((cp1 == (const unsigned char *) s1.fname)
+	  || (cp2 == (const unsigned char *) s2.fname))
+	return ((cp2 == (const unsigned char *) s2.fname)
+		< (cp1 == (const unsigned char *) s1.fname));
 
       /* Character of current path component the same?  */
       else if (*cp1 != *cp2)
-	return *cp1 - *cp2;
+	return *cp1 < *cp2;
     }
 }
 
@@ -9545,7 +9544,7 @@
   htab_traverse (file_table, file_name_acquire, &fnad);
   gcc_assert (fnad.used_files == fnad.max_files);
 
-  qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
+  std::sort (files, files + numfiles, file_info_cmp);
 
   /* Find all the different directories used.  */
   dirs[0].path = files[0].path;
Index: gcc/sel-sched-ir.c
===================================================================
--- gcc/sel-sched-ir.c	(revisão 4)
+++ gcc/sel-sched-ir.c	(cópia de trabalho)
@@ -44,6 +44,8 @@
 #include "langhooks.h"
 #include "rtlhooks-def.h"
 
+#include <algorithm>
+
 #ifdef INSN_SCHEDULING
 #include "sel-sched-ir.h"
 /* We don't have to use it except for sel_print_insn.  */
@@ -942,10 +944,10 @@
 #ifdef ENABLE_CHECKING
 /* This is used as a qsort callback for sorting regset pool stacks.
    X and XX are addresses of two regsets.  They are never equal.  */
-static int
-cmp_v_in_regset_pool (const void *x, const void *xx)
+static bool
+cmp_v_in_regset_pool (const regset& x, const regset& xx)
 {
-  return *((const regset *) x) - *((const regset *) xx);
+  return x < xx;
 }
 #endif
 
@@ -968,8 +970,8 @@
     gcc_assert (n <= nn);
     
     /* Sort both vectors so it will be possible to compare them.  */
-    qsort (v, n, sizeof (*v), cmp_v_in_regset_pool);
-    qsort (vv, nn, sizeof (*vv), cmp_v_in_regset_pool);
+    std::sort (v, v + n, cmp_v_in_regset_pool);
+    std::sort (vv, vv + nn, cmp_v_in_regset_pool);
     
     while (ii < nn)
       {
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c	(revisão 4)
+++ gcc/c-decl.c	(cópia de trabalho)
@@ -66,6 +66,8 @@
 #include "gimple.h"
 #include "plugin.h"
 
+#include <algorithm>
+
 /* In grokdeclarator, distinguish syntactic contexts of declarators.  */
 enum decl_context
 { NORMAL,			/* Ordinary declaration */
@@ -6836,7 +6838,7 @@
 	    TYPE_LANG_SPECIFIC (t) = space;
 	    TYPE_LANG_SPECIFIC (t)->s->len = len;
 	    field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
-	    qsort (field_array, len, sizeof (tree), field_decl_cmp);
+	    std::sort (field_array, field_array + len, field_decl_cmp);
 	  }
       }
   }
Index: gcc/ira-build.c
===================================================================
--- gcc/ira-build.c	(revisão 4)
+++ gcc/ira-build.c	(cópia de trabalho)
@@ -40,6 +40,8 @@
 #include "sparseset.h"
 #include "ira-int.h"
 
+#include <algorithm>
+
 static ira_copy_t find_allocno_copy (ira_allocno_t, ira_allocno_t, rtx,
 				     ira_loop_tree_node_t);
 
@@ -1680,24 +1682,22 @@
 /* Sort loops for marking them for removal.  We put already marked
    loops first, then less frequent loops next, and then outer loops
    next.  */
-static int
-loop_compare_func (const void *v1p, const void *v2p)
+static bool
+loop_compare_func (ira_loop_tree_node_t l1, ira_loop_tree_node_t l2)
 {
   int diff;
-  ira_loop_tree_node_t l1 = *(const ira_loop_tree_node_t *) v1p;
-  ira_loop_tree_node_t l2 = *(const ira_loop_tree_node_t *) v2p;
 
   ira_assert (l1->parent != NULL && l2->parent != NULL);
   if (l1->to_remove_p && ! l2->to_remove_p)
-    return -1;
+    return true;
   if (! l1->to_remove_p && l2->to_remove_p)
-    return 1;
+    return false;
   if ((diff = l1->loop->header->frequency - l2->loop->header->frequency) != 0)
-    return diff;
+    return diff < 0;
   if ((diff = (int) loop_depth (l1->loop) - (int) loop_depth (l2->loop)) != 0)
-    return diff;
+    return diff < 0;
   /* Make sorting stable.  */
-  return l1->loop->num - l2->loop->num;
+  return l1->loop->num < l2->loop->num;
 }
 
 
@@ -1733,7 +1733,7 @@
 	  = (low_pressure_loop_node_p (ira_loop_nodes[i].parent)
 	     && low_pressure_loop_node_p (&ira_loop_nodes[i]));
       }
-  qsort (sorted_loops, n, sizeof (ira_loop_tree_node_t), loop_compare_func);
+  std::sort (sorted_loops, sorted_loops + n, loop_compare_func);
   for (i = 0; n - i + 1 > IRA_MAX_LOOPS_NUM; i++)
     {
       sorted_loops[i]->to_remove_p = true;
@@ -1838,23 +1838,21 @@
 }
 
 /* Sort allocnos according to their order in regno allocno list.  */
-static int
-regno_allocno_order_compare_func (const void *v1p, const void *v2p)
+static bool
+regno_allocno_order_compare_func (ira_allocno_t a1, ira_allocno_t a2)
 {
-  ira_allocno_t a1 = *(const ira_allocno_t *) v1p;
-  ira_allocno_t a2 = *(const ira_allocno_t *) v2p;
   ira_loop_tree_node_t n1 = ALLOCNO_LOOP_TREE_NODE (a1);
   ira_loop_tree_node_t n2 = ALLOCNO_LOOP_TREE_NODE (a2);
 
   if (loop_is_inside_p (n1, n2))
-    return -1;
+    return true;
   else if (loop_is_inside_p (n2, n1))
-    return 1;
+    return false;
   /* If allocnos are equally good, sort by allocno numbers, so that
      the results of qsort leave nothing to chance.  We put allocnos
      with higher number first in the list because it is the original
      order for allocnos from loops on the same levels.  */
-  return ALLOCNO_NUM (a2) - ALLOCNO_NUM (a1);
+  return ALLOCNO_NUM (a2) < ALLOCNO_NUM (a1);
 }
 
 /* This array is used to sort allocnos to restore allocno order in
@@ -1873,7 +1871,7 @@
        a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
     regno_allocnos[n++] = a;
   ira_assert (n > 0);
-  qsort (regno_allocnos, n, sizeof (ira_allocno_t), 
+  std::sort (regno_allocnos, regno_allocnos + n,
 	 regno_allocno_order_compare_func);
   for (i = 1; i < n; i++)
     ALLOCNO_NEXT_REGNO_ALLOCNO (regno_allocnos[i - 1]) = regno_allocnos[i];
@@ -2226,21 +2224,19 @@
    Allocnos with the same cove class are ordered according their start
    (min).  Allocnos with the same start are ordered according their
    finish (max).  */
-static int
-allocno_range_compare_func (const void *v1p, const void *v2p)
+static bool
+allocno_range_compare_func (ira_allocno_t a1, ira_allocno_t a2)
 {
   int diff;
-  ira_allocno_t a1 = *(const ira_allocno_t *) v1p;
-  ira_allocno_t a2 = *(const ira_allocno_t *) v2p;
 
   if (flag_ira_algorithm != IRA_ALGORITHM_PRIORITY
       && (diff = ALLOCNO_COVER_CLASS (a1) - ALLOCNO_COVER_CLASS (a2)) != 0)
-    return diff;
+    return diff < 0;
   if ((diff = ALLOCNO_MIN (a1) - ALLOCNO_MIN (a2)) != 0)
-    return diff;
+    return diff < 0;
   if ((diff = ALLOCNO_MAX (a1) - ALLOCNO_MAX (a2)) != 0)
-     return diff;
-  return ALLOCNO_NUM (a1) - ALLOCNO_NUM (a2);
+     return diff < 0;
+  return ALLOCNO_NUM (a1) < ALLOCNO_NUM (a2);
 }
 
 /* Sort ira_conflict_id_allocno_map and set up conflict id of
@@ -2255,7 +2251,7 @@
   num = 0;
   FOR_EACH_ALLOCNO (a, ai)
     ira_conflict_id_allocno_map[num++] = a;
-  qsort (ira_conflict_id_allocno_map, num, sizeof (ira_allocno_t),
+  std::sort (ira_conflict_id_allocno_map, ira_conflict_id_allocno_map + num,
 	 allocno_range_compare_func);
   for (i = 0; i < num; i++)
     if ((a = ira_conflict_id_allocno_map[i]) != NULL)
Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c	(revisão 4)
+++ gcc/gimplify.c	(cópia de trabalho)
@@ -54,6 +54,7 @@
 #include "gimple.h"
 #include "tree-pass.h"
 
+#include <algorithm>
 
 enum gimplify_omp_var_data
 {
@@ -1446,19 +1447,16 @@
    made sure that case ranges do not overlap, it is enough to only compare
    the CASE_LOW values of each case label.  */
 
-static int
-compare_case_labels (const void *p1, const void *p2)
+static bool
+compare_case_labels (const tree& case1, const tree& case2)
 {
-  const_tree const case1 = *(const_tree const*)p1;
-  const_tree const case2 = *(const_tree const*)p2;
-
   /* The 'default' case label always goes first.  */
   if (!CASE_LOW (case1))
-    return -1;
+    return true;
   else if (!CASE_LOW (case2))
-    return 1;
+    return false;
   else
-    return tree_int_cst_compare (CASE_LOW (case1), CASE_LOW (case2));
+    return tree_int_cst_compare (CASE_LOW (case1), CASE_LOW (case2)) < 0;
 }
 
 
@@ -1468,8 +1466,8 @@
 sort_case_labels (VEC(tree,heap)* label_vec)
 {
   size_t len = VEC_length (tree, label_vec);
-  qsort (VEC_address (tree, label_vec), len, sizeof (tree),
-         compare_case_labels);
+  std::sort (VEC_address (tree, label_vec),
+         VEC_address (tree, label_vec) + len, compare_case_labels);
 }
 
 
Index: gcc/tree-ssa-coalesce.c
===================================================================
--- gcc/tree-ssa-coalesce.c	(revisão 4)
+++ gcc/tree-ssa-coalesce.c	(cópia de trabalho)
@@ -33,6 +33,7 @@
 #include "tree-ssa-live.h"
 #include "toplev.h"
 
+#include <algorithm>
 
 /* This set of routines implements a coalesce_list.  This is an object which
    is used to track pairs of ssa_names which are desirable to coalesce
@@ -329,25 +330,23 @@
 
 /* Comparison function to allow qsort to sort P1 and P2 in Ascending order.  */
 
-static int 
-compare_pairs (const void *p1, const void *p2)
+static bool
+compare_pairs (const_coalesce_pair_p p1, const_coalesce_pair_p p2)
 {
-  const_coalesce_pair_p const *const pp1 = (const_coalesce_pair_p const *) p1;
-  const_coalesce_pair_p const *const pp2 = (const_coalesce_pair_p const *) p2;
   int result;
 
-  result = (* pp1)->cost - (* pp2)->cost;
+  result = p1->cost - p2->cost;
   /* Since qsort does not guarantee stability we use the elements
      as a secondary key.  This provides us with independence from
      the host's implementation of the sorting algorithm.  */
   if (result == 0)
     {
-      result = (* pp2)->first_element - (* pp1)->first_element;
+      result = p2->first_element - p1->first_element;
       if (result == 0)
-	result = (* pp2)->second_element - (* pp1)->second_element;
+	result = p2->second_element - p1->second_element;
     }
 
-  return result;
+  return result < 0;
 }
 
 
@@ -452,7 +451,7 @@
 
   /* Only call qsort if there are more than 2 items.  */
   if (num > 2)
-      qsort (cl->sorted, num, sizeof (coalesce_pair_p), compare_pairs);
+      std::sort (cl->sorted, cl->sorted + num, compare_pairs);
 }
 
 
Index: gcc/ggc-common.c
===================================================================
--- gcc/ggc-common.c	(revisão 4)
+++ gcc/ggc-common.c	(cópia de trabalho)
@@ -33,6 +33,8 @@
 #include "plugin.h"
 #include "vec.h"
 
+#include <algorithm>
+
 #ifdef HAVE_SYS_RESOURCE_H
 # include <sys/resource.h>
 #endif
@@ -65,7 +67,6 @@
 static int saving_htab_eq (const void *, const void *);
 static int call_count (void **, void *);
 static int call_alloc (void **, void *);
-static int compare_ptr_data (const void *, const void *);
 static void relocate_ptrs (void *, void *);
 static void write_pch_globals (const struct ggc_root_tab * const *tab,
 			       struct traversal_state *state);
@@ -397,13 +398,11 @@
 
 /* Callback for qsort.  */
 
-static int
-compare_ptr_data (const void *p1_p, const void *p2_p)
+static bool
+compare_ptr_data (const ptr_data *p1, const ptr_data *p2)
 {
-  const struct ptr_data *const p1 = *(const struct ptr_data *const *)p1_p;
-  const struct ptr_data *const p2 = *(const struct ptr_data *const *)p2_p;
   return (((size_t)p1->new_addr > (size_t)p2->new_addr)
-	  - ((size_t)p1->new_addr < (size_t)p2->new_addr));
+	  < ((size_t)p1->new_addr < (size_t)p2->new_addr));
 }
 
 /* Callbacks for note_ptr_fn.  */
@@ -514,7 +513,7 @@
   state.ptrs = XNEWVEC (struct ptr_data *, state.count);
   state.ptrs_i = 0;
   htab_traverse (saving_htab, call_alloc, &state);
-  qsort (state.ptrs, state.count, sizeof (*state.ptrs), compare_ptr_data);
+  std::sort (state.ptrs, state.ptrs + state.count, compare_ptr_data);
 
   /* Write out all the scalar variables.  */
   for (rt = gt_pch_scalar_rtab; *rt; rt++)
@@ -961,36 +960,28 @@
 }
 
 /* Helper for qsort; sort descriptors by amount of memory consumed.  */
-static int
-final_cmp_statistic (const void *loc1, const void *loc2)
+static bool
+final_cmp_statistic (const loc_descriptor *l1, const loc_descriptor *l2)
 {
-  const struct loc_descriptor *const l1 =
-    *(const struct loc_descriptor *const *) loc1;
-  const struct loc_descriptor *const l2 =
-    *(const struct loc_descriptor *const *) loc2;
   long diff;
   diff = ((long)(l1->allocated + l1->overhead - l1->freed) -
 	  (l2->allocated + l2->overhead - l2->freed));
-  return diff > 0 ? 1 : diff < 0 ? -1 : 0;
+  return diff < 0;
 }
 
 /* Helper for qsort; sort descriptors by amount of memory consumed.  */
-static int
-cmp_statistic (const void *loc1, const void *loc2)
+static bool
+cmp_statistic (const loc_descriptor *l1, const loc_descriptor *l2)
 {
-  const struct loc_descriptor *const l1 =
-    *(const struct loc_descriptor *const *) loc1;
-  const struct loc_descriptor *const l2 =
-    *(const struct loc_descriptor *const *) loc2;
   long diff;
 
   diff = ((long)(l1->allocated + l1->overhead - l1->freed - l1->collected) -
 	  (l2->allocated + l2->overhead - l2->freed - l2->collected));
   if (diff)
-    return diff > 0 ? 1 : diff < 0 ? -1 : 0;
+    return diff < 0;
   diff =  ((long)(l1->allocated + l1->overhead - l1->freed) -
 	   (l2->allocated + l2->overhead - l2->freed));
-  return diff > 0 ? 1 : diff < 0 ? -1 : 0;
+  return diff < 0;
 }
 
 /* Collect array of the descriptors from hashtable.  */
@@ -1024,8 +1015,8 @@
 	   "source location", "Garbage", "Freed", "Leak", "Overhead", "Times");
   fprintf (stderr, "-------------------------------------------------------\n");
   htab_traverse (loc_hash, add_statistics, &nentries);
-  qsort (loc_array, nentries, sizeof (*loc_array),
-	 final ? final_cmp_statistic : cmp_statistic);
+  std::sort (loc_array, loc_array+ nentries,
+	 final ? final_statistic_less : cmp_statistic);
   for (i = 0; i < nentries; i++)
     {
       struct loc_descriptor *d = loc_array[i];
Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c	(revisão 4)
+++ gcc/cfgexpand.c	(cópia de trabalho)
@@ -44,6 +44,7 @@
 #include "target.h"
 #include "ssaexpand.h"
 
+#include <algorithm>
 
 /* This variable holds information helping the rewriting of SSA trees
    into RTL.  */
@@ -751,20 +752,20 @@
 /* A subroutine of partition_stack_vars.  A comparison function for qsort,
    sorting an array of indices by the size and type of the object.  */
 
-static int
-stack_var_size_cmp (const void *a, const void *b)
+static bool
+stack_var_size_cmp (size_t a, size_t b)
 {
-  HOST_WIDE_INT sa = stack_vars[*(const size_t *)a].size;
-  HOST_WIDE_INT sb = stack_vars[*(const size_t *)b].size;
+  HOST_WIDE_INT sa = stack_vars[a].size;
+  HOST_WIDE_INT sb = stack_vars[b].size;
   tree decla, declb;
   unsigned int uida, uidb;
 
   if (sa < sb)
-    return -1;
+    return true;
   if (sa > sb)
-    return 1;
-  decla = stack_vars[*(const size_t *)a].decl;
-  declb = stack_vars[*(const size_t *)b].decl;
+    return false;
+  decla = stack_vars[a].decl;
+  declb = stack_vars[b].decl;
   /* For stack variables of the same size use and id of the decls
      to make the sort stable.  Two SSA names are compared by their
      version, SSA names come before non-SSA names, and two normal
@@ -774,17 +775,17 @@
       if (TREE_CODE (declb) == SSA_NAME)
 	uida = SSA_NAME_VERSION (decla), uidb = SSA_NAME_VERSION (declb);
       else
-	return -1;
+	return true;
     }
   else if (TREE_CODE (declb) == SSA_NAME)
-    return 1;
+    return false;
   else
     uida = DECL_UID (decla), uidb = DECL_UID (declb);
   if (uida < uidb)
-    return -1;
+    return true;
   if (uida > uidb)
-    return 1;
-  return 0;
+    return false;
+  return false;
 }
 
 
@@ -977,7 +978,7 @@
   if (n == 1)
     return;
 
-  qsort (stack_vars_sorted, n, sizeof (size_t), stack_var_size_cmp);
+  std::sort (stack_vars_sorted, stack_vars_sorted+ n, stack_var_size_cmp);
 
   /* Special case: detect when all variables conflict, and thus we can't
      do anything during the partitioning loop.  It isn't uncommon (with
Index: gcc/tree-sra.c
===================================================================
--- gcc/tree-sra.c	(revisão 4)
+++ gcc/tree-sra.c	(cópia de trabalho)
@@ -88,6 +88,8 @@
 #include "target.h"
 #include "flags.h"
 
+#include <algorithm>
+
 /* Enumeration of all aggregate reductions we can do.  */
 enum sra_mode { SRA_MODE_EARLY_INTRA, /* early intraprocedural SRA */
 		SRA_MODE_INTRA };	     /* late intraprocedural SRA */
@@ -907,46 +909,41 @@
    access is considered smaller than another if it has smaller offset or if the
    offsets are the same but is size is bigger. */
 
-static int
-compare_access_positions (const void *a, const void *b)
+static bool
+compare_access_positions (access_p f1, access_p f2)
 {
-  const access_p *fp1 = (const access_p *) a;
-  const access_p *fp2 = (const access_p *) b;
-  const access_p f1 = *fp1;
-  const access_p f2 = *fp2;
-
   if (f1->offset != f2->offset)
-    return f1->offset < f2->offset ? -1 : 1;
+    return f1->offset < f2->offset;
 
   if (f1->size == f2->size)
     {
       /* Put any non-aggregate type before any aggregate type.  */
       if (!is_gimple_reg_type (f1->type)
 	       && is_gimple_reg_type (f2->type))
-	return 1;
+	return false;
       else if (is_gimple_reg_type (f1->type)
 	       && !is_gimple_reg_type (f2->type))
-	return -1;
+	return true;
       /* Put the integral type with the bigger precision first.  */
       else if (INTEGRAL_TYPE_P (f1->type)
 	  && INTEGRAL_TYPE_P (f2->type))
-	return TYPE_PRECISION (f1->type) > TYPE_PRECISION (f2->type) ? -1 : 1;
+	return TYPE_PRECISION (f1->type) > TYPE_PRECISION (f2->type);
       /* Put any integral type with non-full precision last.  */
       else if (INTEGRAL_TYPE_P (f1->type)
 	       && (TREE_INT_CST_LOW (TYPE_SIZE (f1->type))
 		   != TYPE_PRECISION (f1->type)))
-	return 1;
+	return false;
       else if (INTEGRAL_TYPE_P (f2->type)
 	       && (TREE_INT_CST_LOW (TYPE_SIZE (f2->type))
 		   != TYPE_PRECISION (f2->type)))
-	return -1;
+	return true;
       /* Stabilize the sort.  */
-      return TYPE_UID (f1->type) - TYPE_UID (f2->type);
+      return TYPE_UID (f1->type) < TYPE_UID (f2->type);
     }
 
   /* We want the bigger accesses first, thus the opposite operator in the next
      line: */
-  return f1->size > f2->size ? -1 : 1;
+  return f1->size > f2->size;
 }
 
 
@@ -1196,7 +1193,8 @@
   access_count = VEC_length (access_p, access_vec);
 
   /* Sort by <OFFSET, SIZE>.  */
-  qsort (VEC_address (access_p, access_vec), access_count, sizeof (access_p),
+  std::sort (VEC_address (access_p, access_vec),
+         VEC_address (access_p, access_vec) + access_count,
 	 compare_access_positions);
 
   i = 0;
Index: gcc/tree-predcom.c
===================================================================
--- gcc/tree-predcom.c	(revisão 4)
+++ gcc/tree-predcom.c	(cópia de trabalho)
@@ -202,6 +202,8 @@
 #include "tree-affine.h"
 #include "tree-inline.h"
 
+#include <algorithm>
+
 /* The maximum number of iterations between the considered memory
    references.  */
 
@@ -893,17 +895,15 @@
 /* Compares two drefs A and B by their offset and position.  Callback for
    qsort.  */
 
-static int
-order_drefs (const void *a, const void *b)
+static bool
+order_drefs (dref a, dref b)
 {
-  const dref *const da = (const dref *) a;
-  const dref *const db = (const dref *) b;
-  int offcmp = double_int_scmp ((*da)->offset, (*db)->offset);
+  int offcmp = double_int_scmp (a->offset, b->offset);
 
   if (offcmp != 0)
-    return offcmp;
+    return offcmp < 0;
 
-  return (*da)->pos - (*db)->pos;
+  return a->pos < b->pos;
 }
 
 /* Returns root of the CHAIN.  */
@@ -1189,8 +1189,9 @@
       return;
     }
 
-  qsort (VEC_address (dref, comp->refs), VEC_length (dref, comp->refs),
-	 sizeof (dref), order_drefs);
+  std::sort (VEC_address (dref, comp->refs),
+         VEC_address (dref, comp->refs) + VEC_length (dref, comp->refs),
+	 order_drefs);
 
   for (i = 0; VEC_iterate (dref, comp->refs, i, a); i++)
     {
Index: gcc/ira.c
===================================================================
--- gcc/ira.c	(revisão 4)
+++ gcc/ira.c	(cópia de trabalho)
@@ -324,6 +324,7 @@
 #include "ggc.h"
 #include "ira-int.h"
 
+#include <algorithm>
 
 /* A modified value of flag `-fira-verbose' used internally.  */
 int internal_flag_ira_verbose;
@@ -925,19 +926,17 @@
 static int cover_class_order[N_REG_CLASSES];
 
 /* The function used to sort the important classes.  */
-static int
-comp_reg_classes_func (const void *v1p, const void *v2p)
+static bool
+comp_reg_classes_func (reg_class cl1, reg_class cl2)
 {
-  enum reg_class cl1 = *(const enum reg_class *) v1p;
-  enum reg_class cl2 = *(const enum reg_class *) v2p;
   int diff;
 
   cl1 = ira_class_translate[cl1];
   cl2 = ira_class_translate[cl2];
   if (cl1 != NO_REGS && cl2 != NO_REGS
       && (diff = cover_class_order[cl1] - cover_class_order[cl2]) != 0)
-    return diff;
-  return (int) cl1 - (int) cl2;
+    return diff < 0;
+  return (int) cl1 < (int) cl2;
 }
 
 /* Reorder important classes according to the order of their cover
@@ -951,8 +950,9 @@
     cover_class_order[i] = -1;
   for (i = 0; i < ira_reg_class_cover_size; i++)
     cover_class_order[ira_reg_class_cover[i]] = i;
-  qsort (ira_important_classes, ira_important_classes_num,
-	 sizeof (enum reg_class), comp_reg_classes_func);
+  std::sort (ira_important_classes,
+         ira_important_classes + ira_important_classes_num,
+	 comp_reg_classes_func);
   for (i = 0; i < ira_important_classes_num; i++)
     ira_important_class_nums[ira_important_classes[i]] = i;
 }
Index: gcc/var-tracking.c
===================================================================
--- gcc/var-tracking.c	(revisão 4)
+++ gcc/var-tracking.c	(cópia de trabalho)
@@ -107,6 +107,8 @@
 #include "timevar.h"
 #include "tree-pass.h"
 
+#include <algorithm>
+
 /* Type of micro operation.  */
 enum micro_operation_type
 {
@@ -340,7 +342,6 @@
 static void dataflow_set_init (dataflow_set *);
 static void dataflow_set_clear (dataflow_set *);
 static void dataflow_set_copy (dataflow_set *, dataflow_set *);
-static int variable_union_info_cmp_pos (const void *, const void *);
 static int variable_union (void **, void *);
 static int variable_canonicalize (void **, void *);
 static void dataflow_set_union (dataflow_set *, dataflow_set *);
@@ -1214,18 +1215,13 @@
 
 /* Compare function for qsort, order the structures by POS element.  */
 
-static int
-variable_union_info_cmp_pos (const void *n1, const void *n2)
+static bool
+variable_union_info_cmp_pos (const variable_union_info& i1, const variable_union_info& i2)
 {
-  const struct variable_union_info *const i1 =
-    (const struct variable_union_info *) n1;
-  const struct variable_union_info *const i2 =
-    ( const struct variable_union_info *) n2;
-
-  if (i1->pos != i2->pos)
-    return i1->pos - i2->pos;
+  if (i1.pos != i2.pos)
+    return i1.pos < i2.pos;
   
-  return (i1->pos_dst - i2->pos_dst);
+  return (i1.pos_dst < i2.pos_dst);
 }
 
 /* Compute union of location parts of variable *SLOT and the same variable
@@ -1494,8 +1490,7 @@
 		}
 	      else
 		{
-		  qsort (vui, n, sizeof (struct variable_union_info),
-			 variable_union_info_cmp_pos);
+		  std::sort (vui, vui + n, variable_union_info_cmp_pos);
 
 		  /* Reconnect the nodes in sorted order.  */
 		  for (ii = 1; ii < n; ii++)
Index: gcc/system.h
===================================================================
--- gcc/system.h	(revisão 4)
+++ gcc/system.h	(cópia de trabalho)
@@ -662,12 +662,12 @@
 #ifdef IN_GCC
 #undef calloc
 #undef strdup
- #pragma GCC poison calloc strdup
+// #pragma GCC poison calloc strdup
 
 #if !defined(FLEX_SCANNER) && !defined(YYBISON)
 #undef malloc
 #undef realloc
- #pragma GCC poison malloc realloc
+// #pragma GCC poison malloc realloc
 #endif
 
 /* Old target macros that have moved to the target hooks structure.  */
Index: gcc/c-common.c
===================================================================
--- gcc/c-common.c	(revisão 4)
+++ gcc/c-common.c	(cópia de trabalho)
@@ -53,6 +53,8 @@
 #include "fixed-value.h"
 #include "libfuncs.h"
 
+#include <algorithm>
+
 cpp_reader *parse_in;		/* Declared in c-pragma.h.  */
 
 /* The following symbols are subsumed in the c_global_trees array, and
@@ -535,7 +537,6 @@
 static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT);
 static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT);
 static bool get_nonnull_operand (tree, unsigned HOST_WIDE_INT *);
-static int resort_field_decl_cmp (const void *, const void *);
 
 /* Reserved words.  The third field is a mask: keywords are disabled
    if they match the mask.
@@ -8054,22 +8055,19 @@
 
 /* Function to help qsort sort FIELD_DECLs by name order.  */
 
-int
-field_decl_cmp (const void *x_p, const void *y_p)
+bool
+field_decl_cmp (const tree& x, const tree& y)
 {
-  const tree *const x = (const tree *const) x_p;
-  const tree *const y = (const tree *const) y_p;
-
-  if (DECL_NAME (*x) == DECL_NAME (*y))
+  if (DECL_NAME (x) == DECL_NAME (y))
     /* A nontype is "greater" than a type.  */
-    return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
-  if (DECL_NAME (*x) == NULL_TREE)
-    return -1;
-  if (DECL_NAME (*y) == NULL_TREE)
-    return 1;
-  if (DECL_NAME (*x) < DECL_NAME (*y))
-    return -1;
-  return 1;
+    return (TREE_CODE (y) == TYPE_DECL) < (TREE_CODE (x) == TYPE_DECL);
+  if (DECL_NAME (x) == NULL_TREE)
+    return true;
+  if (DECL_NAME (y) == NULL_TREE)
+    return false;
+  if (DECL_NAME (x) < DECL_NAME (y))
+    return true;
+  return false;
 }
 
 static struct {
@@ -8080,28 +8078,25 @@
 /* This routine compares two fields like field_decl_cmp but using the
 pointer operator in resort_data.  */
 
-static int
-resort_field_decl_cmp (const void *x_p, const void *y_p)
+static bool
+resort_field_decl_cmp (const tree& x, const tree& y)
 {
-  const tree *const x = (const tree *const) x_p;
-  const tree *const y = (const tree *const) y_p;
-
-  if (DECL_NAME (*x) == DECL_NAME (*y))
+  if (DECL_NAME (x) == DECL_NAME (y))
     /* A nontype is "greater" than a type.  */
-    return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
-  if (DECL_NAME (*x) == NULL_TREE)
-    return -1;
-  if (DECL_NAME (*y) == NULL_TREE)
-    return 1;
+    return (TREE_CODE (y) == TYPE_DECL) < (TREE_CODE (x) == TYPE_DECL);
+  if (DECL_NAME (x) == NULL_TREE)
+    return true;
+  if (DECL_NAME (y) == NULL_TREE)
+    return false;
   {
-    tree d1 = DECL_NAME (*x);
-    tree d2 = DECL_NAME (*y);
+    tree d1 = DECL_NAME (x);
+    tree d2 = DECL_NAME (y);
     resort_data.new_value (&d1, resort_data.cookie);
     resort_data.new_value (&d2, resort_data.cookie);
     if (d1 < d2)
-      return -1;
+      return true;
   }
-  return 1;
+  return false;
 }
 
 /* Resort DECL_SORTED_FIELDS because pointers have been reordered.  */
@@ -8115,8 +8110,7 @@
   struct sorted_fields_type *sf = (struct sorted_fields_type *) obj;
   resort_data.new_value = new_value;
   resort_data.cookie = cookie;
-  qsort (&sf->elts[0], sf->len, sizeof (tree),
-	 resort_field_decl_cmp);
+  std::sort (&sf->elts[0], &sf->elts[0] + sf->len, resort_field_decl_cmp);
 }
 
 /* Subroutine of c_parse_error.
Index: gcc/c-common.h
===================================================================
--- gcc/c-common.h	(revisão 4)
+++ gcc/c-common.h	(cópia de trabalho)
@@ -424,7 +424,7 @@
 
 extern int c_expand_decl (tree);
 
-extern int field_decl_cmp (const void *, const void *);
+extern bool field_decl_cmp (const tree&, const tree&);
 extern void resort_sorted_fields (void *, void *, gt_pointer_operator,
 				  void *);
 extern bool has_c_linkage (const_tree decl);
Index: gcc/tree-ssa-structalias.c
===================================================================
--- gcc/tree-ssa-structalias.c	(revisão 4)
+++ gcc/tree-ssa-structalias.c	(cópia de trabalho)
@@ -50,6 +50,8 @@
 #include "alias.h"
 #include "pointer-set.h"
 
+#include <algorithm>
+
 /* The idea behind this analyzer is to generate set constraints from the
    program, then solve the resulting constraints in order to generate the
    points-to sets.
@@ -4138,34 +4140,32 @@
 
 /* qsort comparison function for two fieldoff's PA and PB */
 
-static int
-fieldoff_compare (const void *pa, const void *pb)
+static bool
+fieldoff_compare (const fieldoff_s& foa, const fieldoff_s& fob)
 {
-  const fieldoff_s *foa = (const fieldoff_s *)pa;
-  const fieldoff_s *fob = (const fieldoff_s *)pb;
   unsigned HOST_WIDE_INT foasize, fobsize;
 
-  if (foa->offset < fob->offset)
-    return -1;
-  else if (foa->offset > fob->offset)
-    return 1;
+  if (foa.offset < fob.offset)
+    return true;
+  else if (foa.offset > fob.offset)
+    return false;
 
-  foasize = foa->size;
-  fobsize = fob->size;
+  foasize = foa.size;
+  fobsize = fob.size;
   if (foasize < fobsize)
-    return -1;
+    return true;
   else if (foasize > fobsize)
-    return 1;
-  return 0;
+    return false;
+  return false;
 }
 
 /* Sort a fieldstack according to the field offset and sizes.  */
 static void
 sort_fieldstack (VEC(fieldoff_s,heap) *fieldstack)
 {
-  qsort (VEC_address (fieldoff_s, fieldstack),
-	 VEC_length (fieldoff_s, fieldstack),
-	 sizeof (fieldoff_s),
+  const size_t count = VEC_length (fieldoff_s, fieldstack);
+  std::sort (VEC_address (fieldoff_s, fieldstack),
+         VEC_address (fieldoff_s, fieldstack) + count,
 	 fieldoff_compare);
 }
 
Index: gcc/tree-ssa-reassoc.c
===================================================================
--- gcc/tree-ssa-reassoc.c	(revisão 4)
+++ gcc/tree-ssa-reassoc.c	(cópia de trabalho)
@@ -40,6 +40,8 @@
 #include "cfgloop.h"
 #include "flags.h"
 
+#include <algorithm>
+
 /*  This is a simple global reassociation pass.  It is, in part, based
     on the LLVM pass of the same name (They do some things more/less
     than we do, in different orders, etc).
@@ -317,26 +319,23 @@
 
 /* qsort comparison function to sort operand entries PA and PB by rank
    so that the sorted array is ordered by rank in decreasing order.  */
-static int
-sort_by_operand_rank (const void *pa, const void *pb)
+static bool
+sort_by_operand_rank (operand_entry_t oea, operand_entry_t oeb)
 {
-  const operand_entry_t oea = *(const operand_entry_t *)pa;
-  const operand_entry_t oeb = *(const operand_entry_t *)pb;
-
   /* It's nicer for optimize_expression if constants that are likely
      to fold when added/multiplied//whatever are put next to each
      other.  Since all constants have rank 0, order them by type.  */
   if (oeb->rank == 0 &&  oea->rank == 0)
-    return constant_type (oeb->op) - constant_type (oea->op);
+    return constant_type (oeb->op) < constant_type (oea->op);
 
   /* Lastly, make sure the versions that are the same go next to each
      other.  We use SSA_NAME_VERSION because it's stable.  */
   if ((oeb->rank - oea->rank == 0)
       && TREE_CODE (oea->op) == SSA_NAME
       && TREE_CODE (oeb->op) == SSA_NAME)
-    return SSA_NAME_VERSION (oeb->op) - SSA_NAME_VERSION (oea->op);
+    return SSA_NAME_VERSION (oeb->op) < SSA_NAME_VERSION (oea->op);
 
-  return oeb->rank - oea->rank;
+  return oeb->rank < oea->rank;
 }
 
 /* Add an operand entry to *OPS for the tree operand OP.  */
@@ -765,12 +764,10 @@
 
 /* Comparison function for qsort sorting oecount elements by count.  */
 
-static int
-oecount_cmp (const void *p1, const void *p2)
+static bool
+oecount_cmp (const oecount& c1, const oecount& c2)
 {
-  const oecount *c1 = (const oecount *)p1;
-  const oecount *c2 = (const oecount *)p2;
-  return c1->cnt - c2->cnt;
+  return c1.cnt < c2.cnt;
 }
 
 /* Walks the linear chain with result *DEF searching for an operation
@@ -1037,8 +1034,11 @@
   htab_delete (ctable);
 
   /* Sort the counting table.  */
-  qsort (VEC_address (oecount, cvec), VEC_length (oecount, cvec),
-	 sizeof (oecount), oecount_cmp);
+  {
+    const size_t n = VEC_length (oecount, cvec);
+    std::sort (VEC_address (oecount, cvec), VEC_address (oecount, cvec) + n,
+	oecount_cmp);
+  }
 
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
@@ -1880,17 +1880,19 @@
 
 	      gimple_set_visited (stmt, true);
 	      linearize_expr_tree (&ops, stmt, true, true);
-	      qsort (VEC_address (operand_entry_t, ops),
-		     VEC_length (operand_entry_t, ops),
-		     sizeof (operand_entry_t),
+	      {
+		const size_t n = VEC_length (operand_entry_t, ops);
+	        std::sort (VEC_address (operand_entry_t, ops),
+	             VEC_address (operand_entry_t, ops) + n,
 		     sort_by_operand_rank);
+	      }
 	      optimize_ops_list (rhs_code, &ops);
 	      if (undistribute_ops_list (rhs_code, &ops,
 					 loop_containing_stmt (stmt)))
 		{
-		  qsort (VEC_address (operand_entry_t, ops),
-			 VEC_length (operand_entry_t, ops),
-			 sizeof (operand_entry_t),
+		  const size_t n = VEC_length (operand_entry_t, ops);
+		  std::sort (VEC_address (operand_entry_t, ops),
+			 VEC_address (operand_entry_t, ops) + n,
 			 sort_by_operand_rank);
 		  optimize_ops_list (rhs_code, &ops);
 		}
Index: gcc/stmt.c
===================================================================
--- gcc/stmt.c	(revisão 4)
+++ gcc/stmt.c	(cópia de trabalho)
@@ -51,7 +51,9 @@
 #include "regs.h"
 #include "alloc-pool.h"
 #include "pretty-print.h"
-\f
+
+#include <algorithm>
+
 /* Functions and data structures for expanding case statements.  */
 
 /* Case label structure, used to hold info on labels within case
@@ -115,7 +117,6 @@
 static void expand_value_return (rtx);
 static int estimate_case_costs (case_node_ptr);
 static bool lshift_cheap_p (void);
-static int case_bit_test_cmp (const void *, const void *);
 static void emit_case_bit_tests (tree, tree, tree, tree, case_node_ptr, rtx);
 static void balance_case_nodes (case_node_ptr *, case_node_ptr);
 static int node_has_low_bound (case_node_ptr, tree);
@@ -2038,17 +2039,14 @@
    number of case nodes, i.e. the node with the most cases gets
    tested first.  */
 
-static int
-case_bit_test_cmp (const void *p1, const void *p2)
+static bool
+case_bit_test_cmp (const case_bit_test& d1, const case_bit_test& d2)
 {
-  const struct case_bit_test *const d1 = (const struct case_bit_test *) p1;
-  const struct case_bit_test *const d2 = (const struct case_bit_test *) p2;
+  if (d2.bits != d1.bits)
+    return d2.bits < d1.bits;
 
-  if (d2->bits != d1->bits)
-    return d2->bits - d1->bits;
-
   /* Stabilize the sort.  */
-  return CODE_LABEL_NUMBER (d2->label) - CODE_LABEL_NUMBER (d1->label);
+  return CODE_LABEL_NUMBER (d2.label) < CODE_LABEL_NUMBER (d1.label);
 }
 
 /*  Expand a switch statement by a short sequence of bit-wise
@@ -2108,7 +2106,7 @@
 	  test[i].lo |= (HOST_WIDE_INT) 1 << j;
     }
 
-  qsort (test, count, sizeof(*test), case_bit_test_cmp);
+  std::sort (test, test + count, case_bit_test_cmp);
 
   index_expr = fold_build2 (MINUS_EXPR, index_type,
 			    fold_convert (index_type, index_expr),
Index: gcc/reload1.c
===================================================================
--- gcc/reload1.c	(revisão 4)
+++ gcc/reload1.c	(cópia de trabalho)
@@ -49,6 +49,8 @@
 #include "target.h"
 #include "emit-rtl.h"
 
+#include <algorithm>
+
 /* This file contains the reload pass of the compiler, which is
    run after register allocation has been done.  It checks that
    each insn is valid (operands required to be in registers really
@@ -415,7 +417,6 @@
 static void reload_as_needed (int);
 static void forget_old_reloads_1 (rtx, const_rtx, void *);
 static void forget_marked_reloads (regset);
-static int reload_reg_class_lower (const void *, const void *);
 static void mark_reload_reg_in_use (unsigned int, int, enum reload_type,
 				    enum machine_mode);
 static void clear_reload_reg_in_use (unsigned int, int, enum reload_type,
@@ -1665,39 +1666,38 @@
   *pprev_reload = 0;
 }
 \f
-/* Comparison function for qsort to decide which of two reloads
-   should be handled first.  *P1 and *P2 are the reload numbers.  */
+/* Strict weak ordering for sort to decide which of two reloads
+   should be handled first.  P1 and P2 are the reload numbers.  */
 
-static int
-reload_reg_class_lower (const void *r1p, const void *r2p)
+static bool
+reload_reg_class_lower (short r1, short r2)
 {
-  int r1 = *(const short *) r1p, r2 = *(const short *) r2p;
   int t;
 
   /* Consider required reloads before optional ones.  */
   t = rld[r1].optional - rld[r2].optional;
   if (t != 0)
-    return t;
+    return t < 0;
 
   /* Count all solitary classes before non-solitary ones.  */
   t = ((reg_class_size[(int) rld[r2].rclass] == 1)
        - (reg_class_size[(int) rld[r1].rclass] == 1));
   if (t != 0)
-    return t;
+    return t < 0;
 
   /* Aside from solitaires, consider all multi-reg groups first.  */
   t = rld[r2].nregs - rld[r1].nregs;
   if (t != 0)
-    return t;
+    return t < 0;
 
   /* Consider reloads in order of increasing reg-class number.  */
   t = (int) rld[r1].rclass - (int) rld[r2].rclass;
   if (t != 0)
-    return t;
+    return t < 0;
 
   /* If reloads are equally urgent, sort by reload number,
      so that the results of qsort leave nothing to chance.  */
-  return r1 - r2;
+  return r1 < r2;
 }
 \f
 /* The cost of spilling each hard reg.  */
@@ -2000,7 +2000,7 @@
   if (dump_file)
     fprintf (dump_file, "Spilling for insn %d.\n", INSN_UID (chain->insn));
 
-  qsort (reload_order, n_reloads, sizeof (short), reload_reg_class_lower);
+  std::sort (&reload_order[0], &reload_order[0] + n_reloads, reload_reg_class_lower);
 
   /* Compute the order of preference for hard registers to spill.  */
 
@@ -5912,7 +5912,7 @@
     }
 
   if (n_reloads > 1)
-    qsort (reload_order, n_reloads, sizeof (short), reload_reg_class_lower);
+    std::sort (&reload_order[0], &reload_order[0] + n_reloads, reload_reg_class_lower);
 
   /* If -O, try first with inheritance, then turning it off.
      If not -O, don't do inheritance.
Index: libcpp/files.c
===================================================================
--- libcpp/files.c	(revisão 4)
+++ libcpp/files.c	(cópia de trabalho)
@@ -32,6 +32,8 @@
 #include "md5.h"
 #include <dirent.h>
 
+#include <algorithm>
+
 /* Variable length record files on VMS will have a stat size that includes
    record control characters that won't be included in the read size.  */
 #ifdef VMS
@@ -193,7 +195,6 @@
 static char *remap_filename (cpp_reader *pfile, _cpp_file *file);
 static char *append_file_to_dir (const char *fname, cpp_dir *dir);
 static bool validate_pch (cpp_reader *, _cpp_file *file, const char *pchname);
-static int pchf_save_compare (const void *e1, const void *e2);
 static int pchf_compare (const void *d_p, const void *e_p);
 static bool check_file_against_entries (cpp_reader *, _cpp_file *, bool);
 
@@ -1258,11 +1259,11 @@
   return 1;
 }
 
-/* Comparison function for qsort.  */
-static int
-report_missing_guard_cmp (const void *p1, const void *p2)
+/* Strict weak ordering for std::sort.  */
+static bool
+ntbs_less (const char *p1, const char *p2)
 {
-  return strcmp (*(const char *const *) p1, *(const char *const *) p2);
+  return strcmp (p1, p2) < 0;
 }
 
 /* Report on all files that might benefit from a multiple include guard.
@@ -1282,8 +1283,7 @@
 
       /* Sort the paths to avoid outputting them in hash table
 	 order.  */
-      qsort (data.paths, data.count, sizeof (const char *),
-	     report_missing_guard_cmp);
+      std::sort (data.paths, data.paths + data.count, ntbs_less);
       fputs (_("Multiple include guards may be useful for:\n"),
 	     stderr);
       for (i = 0; i < data.count; i++)
@@ -1637,12 +1637,12 @@
 
 static struct pchf_data *pchf;
 
-/* A qsort ordering function for pchf_entry structures.  */
+/* A strict weak ordering function for pchf_entry structures.  */
 
-static int
-pchf_save_compare (const void *e1, const void *e2)
+static bool
+pchf_save_less (const pchf_entry& e1, const pchf_entry& e2)
 {
-  return memcmp (e1, e2, sizeof (struct pchf_entry));
+  return memcmp (&e1, &e2, sizeof (struct pchf_entry)) < 0;
 }
 
 /* Create and write to F a pchf_data structure.  */
@@ -1706,8 +1706,7 @@
   result_size = (sizeof (struct pchf_data)
                  + sizeof (struct pchf_entry) * (result->count - 1));
 
-  qsort (result->entries, result->count, sizeof (struct pchf_entry),
-	 pchf_save_compare);
+  std::sort (result->entries, result->entries + result->count, pchf_save_less);
 
   return fwrite (result, result_size, 1, fp) == 1;
 }
Index: libcpp/pch.c
===================================================================
--- libcpp/pch.c	(revisão 4)
+++ libcpp/pch.c	(cópia de trabalho)
@@ -23,13 +23,14 @@
 #include "hashtab.h"
 #include "mkdeps.h"
 
+#include <algorithm>
+
 static int write_macdef (cpp_reader *, cpp_hashnode *, void *);
 static int save_idents (cpp_reader *, cpp_hashnode *, void *);
 static hashval_t hashmem (const void *, size_t);
 static hashval_t cpp_string_hash (const void *);
 static int cpp_string_eq (const void *, const void *);
 static int count_defs (cpp_reader *, cpp_hashnode *, void *);
-static int comp_hashnodes (const void *, const void *);
 static int collect_ht_nodes (cpp_reader *, cpp_hashnode *, void *);
 static int write_defs (cpp_reader *, cpp_hashnode *, void *);
 static int save_macros (cpp_reader *, cpp_hashnode *, void *);
@@ -283,14 +284,13 @@
     }
 }
 
-/* Comparison function for qsort.  The arguments point to pointers of
+/* Strict weak ordering for std::sort.  The arguments point to pointers of
    type ht_hashnode *.  */
-static int
-comp_hashnodes (const void *px, const void *py)
+
+static bool
+hashnodes_less (const cpp_hashnode* x, const cpp_hashnode* y)
 {
-  cpp_hashnode *x = *(cpp_hashnode **) px;
-  cpp_hashnode *y = *(cpp_hashnode **) py;
-  return ustrcmp (NODE_NAME (x), NODE_NAME (y));
+  return ustrcmp (NODE_NAME (x), NODE_NAME (y)) < 0;
 }
 
 /* Write out the remainder of the dependency information.  This should be
@@ -315,7 +315,7 @@
   cpp_forall_identifiers (r, write_defs, ss);
 
   /* Sort the list, copy it into a buffer, and write it out.  */
-  qsort (ss->defs, ss->n_defs, sizeof (cpp_hashnode *), &comp_hashnodes);
+  std::sort (ss->defs, ss->defs + ss->n_defs, hashnodes_less);
   definedstrs = ss->definedstrs = XNEWVEC (unsigned char, ss->hashsize);
   for (i = 0; i < ss->n_defs; ++i)
     {
@@ -536,7 +536,7 @@
   nl.asize = 10;
   nl.defs = XNEWVEC (cpp_hashnode *, nl.asize);
   cpp_forall_identifiers (r, &collect_ht_nodes, &nl);
-  qsort (nl.defs, nl.n_defs, sizeof (cpp_hashnode *), &comp_hashnodes);
+  std::sort (nl.defs, nl.defs + nl.n_defs, hashnodes_less);
 
   /* Loop through nl.defs and undeftab, both of which are sorted lists.
      There should be no matches.  */
Index: libcpp/system.h
===================================================================
--- libcpp/system.h	(revisão 4)
+++ libcpp/system.h	(cópia de trabalho)
@@ -397,8 +397,8 @@
 #undef strdup
 #undef malloc
 #undef realloc
- #pragma GCC poison calloc strdup
- #pragma GCC poison malloc realloc
+// #pragma GCC poison calloc strdup
+// #pragma GCC poison malloc realloc
 
 /* Libiberty macros that are no longer used in GCC.  */
 #undef ANSI_PROTOTYPES

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-29 11:26 ` Pedro Lamarão
@ 2009-08-29 19:42   ` Magnus Fromreide
  2009-08-30 10:37     ` Pedro Lamarão
  2009-08-31 19:06   ` Pedro Lamarão
  1 sibling, 1 reply; 15+ messages in thread
From: Magnus Fromreide @ 2009-08-29 19:42 UTC (permalink / raw)
  To: Pedro Lamarão; +Cc: gcc

On Fri, 2009-08-28 at 18:12 -0300, Pedro Lamarão wrote:
> 2009/8/11 Pedro Lamarão <pedro.lamarao@ccppbrasil.org>:
> 
> > I've recently started my contributions to the gcc-in-cxx project, and
> > eventually decided on the qsort suggestion because it seems the
> > easiest one.
> 
> Attached is a much more extensive patch replacing qsort with std::sort.
> 
> I did not follow the suggestion of using bind to reuse the old
> comparison functions.
> Their "less" variants require less address taking and dereferencing
> and are much smaller.
> These functions are used at only one or two places, each of them --
> perfect for inlining.
> This patch actually reduces the size of the final binary.
> 
> I have not yet made complete size and execution speed measurements, though.
> I've run the test suite and there are some failures; I think many of
> them are not regressions when compared with a pure build with C++.

Why the changes to gcc/system.h where you unpoision malloc and realloc?
Why the changes to libcpp/system.h where you unpoision malloc, realloc,
calloc and strdup?

/MF

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-29 19:42   ` Magnus Fromreide
@ 2009-08-30 10:37     ` Pedro Lamarão
  2009-08-31 16:10       ` Richard Henderson
  0 siblings, 1 reply; 15+ messages in thread
From: Pedro Lamarão @ 2009-08-30 10:37 UTC (permalink / raw)
  To: gcc

2009/8/29 Magnus Fromreide <magfr@lysator.liu.se>:
>
> Why the changes to gcc/system.h where you unpoision malloc and realloc?
> Why the changes to libcpp/system.h where you unpoision malloc, realloc,
> calloc and strdup?

Including <algorithm> requires them for some reason.
I haven't really looked into it.

--
 P.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-30 10:37     ` Pedro Lamarão
@ 2009-08-31 16:10       ` Richard Henderson
  2009-08-31 16:18         ` Pedro Lamarão
  0 siblings, 1 reply; 15+ messages in thread
From: Richard Henderson @ 2009-08-31 16:10 UTC (permalink / raw)
  To: Pedro Lamarão; +Cc: gcc

On 08/29/2009 03:49 PM, Pedro Lamarão wrote:
> 2009/8/29 Magnus Fromreide<magfr@lysator.liu.se>:
>>
>> Why the changes to gcc/system.h where you unpoision malloc and realloc?
>> Why the changes to libcpp/system.h where you unpoision malloc, realloc,
>> calloc and strdup?
>
> Including<algorithm>  requires them for some reason.
> I haven't really looked into it.

You should simply include <algorithm> in system.h before
the poisoning.


r~

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-31 16:10       ` Richard Henderson
@ 2009-08-31 16:18         ` Pedro Lamarão
  2009-08-31 18:36           ` Richard Henderson
  0 siblings, 1 reply; 15+ messages in thread
From: Pedro Lamarão @ 2009-08-31 16:18 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc

2009/8/31 Richard Henderson <rth@redhat.com>:

> On 08/29/2009 03:49 PM, Pedro Lamarão wrote:
>>
>> 2009/8/29 Magnus Fromreide<magfr@lysator.liu.se>:
>>>
>>> Why the changes to gcc/system.h where you unpoision malloc and realloc?
>>> Why the changes to libcpp/system.h where you unpoision malloc, realloc,
>>> calloc and strdup?
>>
>> Including<algorithm>  requires them for some reason.
>> I haven't really looked into it.
>
> You should simply include <algorithm> in system.h before
> the poisoning.

Oh. Right. :-)

For the record, this is the error message I get:

In file included from
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/stl_algo.h:60,
                 from
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/algorithm:62,
                 from ../../libcpp/pch.c:26:
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/cstdlib:78:8:
error: attempt to use poisoned "calloc"
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/cstdlib:85:8:
error: attempt to use poisoned "malloc"
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/cstdlib:91:8:
error: attempt to use poisoned "realloc"
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/cstdlib:112:11:
error: attempt to use poisoned "calloc"
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/cstdlib:119:11:
error: attempt to use poisoned "malloc"
/usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/cstdlib:127:11:
error: attempt to use poisoned "realloc"

I'll try to include cstdlib in system.h to see if that's enough.

--
 P.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-31 16:18         ` Pedro Lamarão
@ 2009-08-31 18:36           ` Richard Henderson
  2009-08-31 18:54             ` Richard Guenther
  0 siblings, 1 reply; 15+ messages in thread
From: Richard Henderson @ 2009-08-31 18:36 UTC (permalink / raw)
  To: Pedro Lamarão; +Cc: gcc

On 08/31/2009 08:26 AM, Pedro Lamarão wrote:
> I'll try to include cstdlib in system.h to see if that's enough.

Note the existing

#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif

You may wish to convert this to

#ifdef __cplusplus
# include <cstdlib>
#elif defined(HAVE_STDLIB_H)
# include <stdlib.h>
#endif

and similarly for all of the other C headers
that the C++ standard wraps.


r~

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-31 18:36           ` Richard Henderson
@ 2009-08-31 18:54             ` Richard Guenther
  2009-08-31 19:01               ` Richard Henderson
  0 siblings, 1 reply; 15+ messages in thread
From: Richard Guenther @ 2009-08-31 18:54 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Pedro Lamarão, gcc

On Mon, Aug 31, 2009 at 6:07 PM, Richard Henderson<rth@redhat.com> wrote:
> On 08/31/2009 08:26 AM, Pedro Lamarão wrote:
>>
>> I'll try to include cstdlib in system.h to see if that's enough.
>
> Note the existing
>
> #ifdef HAVE_STDLIB_H
> # include <stdlib.h>
> #endif
>
> You may wish to convert this to
>
> #ifdef __cplusplus
> # include <cstdlib>
> #elif defined(HAVE_STDLIB_H)
> # include <stdlib.h>
> #endif
>
> and similarly for all of the other C headers
> that the C++ standard wraps.

In which case you'd need a strathegic using namespace std; somewhere.

Richard.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-31 18:54             ` Richard Guenther
@ 2009-08-31 19:01               ` Richard Henderson
  0 siblings, 0 replies; 15+ messages in thread
From: Richard Henderson @ 2009-08-31 19:01 UTC (permalink / raw)
  To: Richard Guenther; +Cc: Pedro Lamarão, gcc

On 08/31/2009 09:09 AM, Richard Guenther wrote:
> In which case you'd need a strathegic using namespace std; somewhere.

system.h?  :-)


r~

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-29 11:26 ` Pedro Lamarão
  2009-08-29 19:42   ` Magnus Fromreide
@ 2009-08-31 19:06   ` Pedro Lamarão
  2009-09-02  0:24     ` Michael Matz
  1 sibling, 1 reply; 15+ messages in thread
From: Pedro Lamarão @ 2009-08-31 19:06 UTC (permalink / raw)
  To: gcc

2009/8/28 Pedro Lamarão <pedro.lamarao@ccppbrasil.org>:

> I have not yet made complete size and execution speed measurements, though.
> I've run the test suite and there are some failures; I think many of
> them are not regressions when compared with a pure build with C++.

Comparing trunk -r151160  and  trunk -t151160 --enable-build-with-cxx
+ patches, these are the sizes of xgcc and g++ before strip:

[psilva@joana obj]$ ls -lh gcc/xgcc gcc/g++
-rwxrwxr-x. 1 psilva psilva 481K Ago 31 12:58 gcc/g++
-rwxrwxr-x. 1 psilva psilva 477K Ago 31 12:58 gcc/xgcc

[psilva@joana obj]$ ls -lh ../../std_sort/obj/gcc/xgcc
../../std_sort/obj/gcc/g++
-rwxrwxr-x. 1 psilva psilva 491K Ago 31 12:33 ../../std_sort/obj/gcc/g++
-rwxrwxr-x. 1 psilva psilva 487K Ago 31 12:33 ../../std_sort/obj/gcc/xgcc

and after strip:

[psilva@joana obj]$ ls -lh gcc/xgcc gcc/g++
-rwxrwxr-x. 1 psilva psilva 221K Ago 31 13:08 gcc/g++
-rwxrwxr-x. 1 psilva psilva 218K Ago 31 13:08 gcc/xgcc

[psilva@joana obj]$ ls -lh ../../std_sort/obj/gcc/xgcc
../../std_sort/obj/gcc/g++
-rwxrwxr-x. 1 psilva psilva 219K Ago 31 13:08 ../../std_sort/obj/gcc/g++
-rwxrwxr-x. 1 psilva psilva 216K Ago 31 13:08 ../../std_sort/obj/gcc/xgcc

Both configurations are basically like this:

[psilva@joana obj]$ gcc/xgcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/opt/gcc-in-cxx
--disable-bootstrap --enable-checking --enable-shared
--enable-threads=posix --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-languages=c,c++
Thread model: posix
gcc version 4.5.0 20090828 (experimental) (GCC)

--
 P.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-08-31 19:06   ` Pedro Lamarão
@ 2009-09-02  0:24     ` Michael Matz
  2009-09-02 12:57       ` Pedro Lamarão
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Matz @ 2009-09-02  0:24 UTC (permalink / raw)
  To: Pedro Lamarão; +Cc: gcc

[-- Attachment #1: Type: TEXT/PLAIN, Size: 792 bytes --]

Hi,

On Mon, 31 Aug 2009, Pedro Lamarão wrote:

> 2009/8/28 Pedro Lamarão <pedro.lamarao@ccppbrasil.org>:
> 
> > I have not yet made complete size and execution speed measurements, though.
> > I've run the test suite and there are some failures; I think many of
> > them are not regressions when compared with a pure build with C++.
> 
> Comparing trunk -r151160  and  trunk -t151160 --enable-build-with-cxx
> + patches, these are the sizes of xgcc and g++ before strip:
> 
> [psilva@joana obj]$ ls -lh gcc/xgcc gcc/g++
> -rwxrwxr-x. 1 psilva psilva 481K Ago 31 12:58 gcc/g++
> -rwxrwxr-x. 1 psilva psilva 477K Ago 31 12:58 gcc/xgcc

That's not the real compiler, only the compiler driver.  Look for files 
named cc1 (the C compiler) and cc1plus (the C++ compiler)  :-)


Ciao,
Michael.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gcc-in-cxx] replacing qsort with std::sort
  2009-09-02  0:24     ` Michael Matz
@ 2009-09-02 12:57       ` Pedro Lamarão
  0 siblings, 0 replies; 15+ messages in thread
From: Pedro Lamarão @ 2009-09-02 12:57 UTC (permalink / raw)
  To: Michael Matz; +Cc: gcc

2009/9/1 Michael Matz <matz@suse.de>:

>> [psilva@joana obj]$ ls -lh gcc/xgcc gcc/g++
>> -rwxrwxr-x. 1 psilva psilva 481K Ago 31 12:58 gcc/g++
>> -rwxrwxr-x. 1 psilva psilva 477K Ago 31 12:58 gcc/xgcc
>
> That's not the real compiler, only the compiler driver.  Look for files
> named cc1 (the C compiler) and cc1plus (the C++ compiler)  :-)

Ah... So the real numbers for stripped binaries are:

-rwxrwxr-x. 1 psilva psilva  42M Ago 31 17:54 std_sort/obj/gcc/cc1plus
-rwxrwxr-x. 1 psilva psilva  38M Ago 31 12:59 trunk/obj/gcc/cc1plus

also:

   text	   data	    bss	    dec	    hex	filename
12174791	  23020	 986004	13183815	 c92b47	std_sort/obj/gcc/cc1plus
11308791	 546960	 461684	12317435	 bbf2fb	trunk/obj/gcc/cc1plus

--
 P.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2009-09-02 12:57 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-12  9:59 [gcc-in-cxx] replacing qsort with std::sort Pedro Lamarão
2009-08-12 13:12 ` Richard Guenther
2009-08-12 14:33   ` Pedro Lamarão
2009-08-12 13:21 ` Ian Lance Taylor
2009-08-29 11:26 ` Pedro Lamarão
2009-08-29 19:42   ` Magnus Fromreide
2009-08-30 10:37     ` Pedro Lamarão
2009-08-31 16:10       ` Richard Henderson
2009-08-31 16:18         ` Pedro Lamarão
2009-08-31 18:36           ` Richard Henderson
2009-08-31 18:54             ` Richard Guenther
2009-08-31 19:01               ` Richard Henderson
2009-08-31 19:06   ` Pedro Lamarão
2009-09-02  0:24     ` Michael Matz
2009-09-02 12:57       ` Pedro Lamarão

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).