Guest User

Untitled

a guest
Apr 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.93 KB | None | 0 0
  1. diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c
  2. index 9eb63c2..6ae3dd8 100644
  3. --- a/gcc/lto/lto-partition.c
  4. +++ b/gcc/lto/lto-partition.c
  5. @@ -34,6 +34,10 @@ along with GCC; see the file COPYING3.  If not see
  6.  #include "ipa-prop.h"
  7.  #include "ipa-inline.h"
  8.  #include "lto-partition.h"
  9. +#include <map>
  10. +#include <set>
  11. +#include <vector>
  12. +#include <algorithm>
  13.  
  14.  vec<ltrans_partition> ltrans_partitions;
  15.  
  16. @@ -446,6 +450,23 @@ add_sorted_nodes (vec<symtab_node *> &next_nodes, ltrans_partition partition)
  17.     the process is undone to the point where the minimal ratio of boundary size
  18.     and in-partition calls was reached.  */
  19.  
  20. +struct var_ref
  21. +{
  22. +  int nrefs;
  23. +  int partition_index;
  24. +};
  25. +
  26. +typedef std::map< std::set<varpool_node *>, var_ref > vars_map_t;
  27. +typedef std::pair< std::set<varpool_node *>, var_ref > vars_pair;
  28. +typedef std::map< std::set<varpool_node *>, var_ref >::iterator vars_map_iter;
  29. +
  30. +/* Compare in non-increasing order.  */
  31. +bool
  32. +cmp_var_ref (const vars_pair& a, const vars_pair& b)
  33. +{
  34. +  return a.second.nrefs > b.second.nrefs;
  35. +}
  36. +
  37.  void
  38.  lto_balanced_map (int n_lto_partitions)
  39.  {
  40. @@ -468,6 +489,8 @@ lto_balanced_map (int n_lto_partitions)
  41.    int current_order = -1;
  42.    int noreorder_pos = 0;
  43.  
  44. +  symtab->dump_file = stderr;
  45. +
  46.    FOR_EACH_VARIABLE (vnode)
  47.      gcc_assert (!vnode->aux);
  48.      
  49. @@ -719,7 +742,7 @@ lto_balanced_map (int n_lto_partitions)
  50.          best_cost, best_internal, best_i);
  51.        /* Partition is too large, unwind into step when best cost was reached and
  52.      start new partition.  */
  53. -      if (partition->insns > 2 * partition_size)
  54. +      if (partition->insns > 2 * partition_size || 1)
  55.     {
  56.       if (best_i != i)
  57.         {
  58. @@ -758,6 +781,122 @@ lto_balanced_map (int n_lto_partitions)
  59.     }
  60.      }
  61.  
  62. +  vars_map_t vars_map;
  63. +
  64. +  std::map< std::set<varpool_node *>, int > partition_map;
  65. +  typedef std::map<std::set<varpool_node *>, int>::iterator partition_map_iter;
  66. +
  67. +  for (unsigned i = 0; i < ltrans_partitions.length (); ++i)
  68. +    {
  69. +      ltrans_partition part = ltrans_partitions[i];
  70. +
  71. +      for (int j = 0; j < lto_symtab_encoder_size (part->encoder); j++)
  72. +   {
  73. +     symtab_node *snode = lto_symtab_encoder_deref (part->encoder, j);
  74. +     if (cgraph_node *cnode = dyn_cast<cgraph_node *> (snode))
  75. +       {
  76. +         fprintf (stderr, "function %s is in partition %d\n", cnode->name (), i);
  77. +         ipa_ref *ref;
  78. +             std::set<varpool_node *> var_set;
  79. +
  80. +         for (int k = 0; cnode->iterate_reference (k, ref); k++)
  81. +       {
  82. +         varpool_node *vnode = dyn_cast<varpool_node *> (ref->referred);
  83. +         if (vnode
  84. +//           && vnode->get_partitioning_class () == SYMBOL_PARTITION
  85. +//           && !symbol_partitioned_p (vnode)
  86. +             && !vnode->no_reorder)
  87. +           var_set.insert (vnode);
  88. +       }
  89. +         if (var_set.size () >= 2)
  90. +       partition_map[var_set]++;
  91. +      
  92. +         var_set.clear ();
  93. +       }
  94. +   }
  95. +
  96. +      for (partition_map_iter p_it = partition_map.begin (); p_it != partition_map.end (); ++p_it)
  97. +   {
  98. +     const std::set<varpool_node *>& var_set = p_it->first;
  99. +     int nrefs = p_it->second;
  100. +
  101. +     struct var_ref& vr = vars_map[var_set];
  102. +     if (vr.nrefs < nrefs)
  103. +       {
  104. +         vr.nrefs = nrefs;
  105. +         vr.partition_index = i;
  106. +       }
  107. +   }
  108. +    }
  109. +
  110. +#if 1
  111. +  fprintf (stderr, "\nvars_map: \n");
  112. +  for (vars_map_iter it = vars_map.begin (); it != vars_map.end (); ++it)
  113. +    {
  114. +      const std::set<varpool_node *>& var_set = it->first;
  115. +      struct var_ref vr = it->second;
  116. +
  117. +      fprintf (stderr, "{");
  118. +      for (std::set<varpool_node *>::const_iterator set_it = var_set.begin (); set_it != var_set.end (); ++set_it)
  119. +   {
  120. +     varpool_node *vnode = *set_it;
  121. +     fprintf (stderr, "%s, ", vnode->name ());
  122. +   }
  123. +      fprintf (stderr, "} -> %d, %d\n", vr.nrefs, vr.partition_index);
  124. +    }
  125. +#endif
  126. +
  127. +  std::vector<vars_pair> vec_vr;
  128. +
  129. +  for (vars_map_iter it = vars_map.begin (); it != vars_map.end (); ++it)
  130. +    vec_vr.push_back (*it);
  131. +
  132. +  std::sort (vec_vr.begin (), vec_vr.end (), cmp_var_ref);
  133. +
  134. +#if 1
  135. +  fprintf (stderr, "\nvars_map in non increasing order:\n");
  136. +  for (std::vector<vars_pair>::iterator it = vec_vr.begin (); it != vec_vr.end (); ++it)
  137. +    {
  138. +      const std::set<varpool_node *>& var_set = it->first;
  139. +      struct var_ref vr = it->second;
  140. +
  141. +      fprintf (stderr, "{");
  142. +      for (std::set<varpool_node *>::const_iterator set_it = var_set.begin (); set_it != var_set.end (); ++set_it)
  143. +   {
  144. +     varpool_node *vnode = *set_it;
  145. +     fprintf (stderr, "%s, ", vnode->name ());
  146. +   }
  147. +      fprintf (stderr, "} -> %d, %d\n", vr.nrefs, vr.partition_index);
  148. +    }
  149. +#endif
  150. +
  151. +  for (std::vector<vars_pair>::iterator it = vec_vr.begin (); it != vec_vr.end (); ++it)
  152. +    {
  153. +      const std::set<varpool_node *>& var_set = it->first;
  154. +      struct var_ref vr = it->second;
  155. +
  156. +      std::vector<varpool_node *> out;
  157. +      out.clear ();
  158. +
  159. +      for (std::set<varpool_node *>::iterator set_it = var_set.begin (); set_it != var_set.end (); ++set_it)
  160. +   {
  161. +     varpool_node *vnode = *set_it;
  162. +//   if (!symbol_partitioned_p (vnode) && vnode->get_partitioning_class () == SYMBOL_PARTITION)
  163. +       out.push_back (vnode);
  164. +   }
  165. +
  166. +      if (out.size () >= 2)
  167. +   {
  168. +     for (std::vector<varpool_node *>::iterator it = out.begin (); it != out.end (); ++it)
  169. +       {
  170. +         varpool_node *vnode = *it;
  171. +         fprintf (stderr, "%s goes to partition %d\n", vnode->name (), vr.partition_index);
  172. +//       if (!symbol_partitioned_p (vnode))
  173. +//     add_symbol_to_partition (ltrans_partitions[vr.partition_index], vnode);
  174. +       }
  175. +   }
  176. +    }
  177. +      
  178.    next_nodes.truncate (0);
  179.  
  180.    /* Varables that are not reachable from the code go into last partition.  */
  181. @@ -776,7 +915,6 @@ lto_balanced_map (int n_lto_partitions)
  182.    while (noreorder_pos < (int)noreorder.length ())
  183.      next_nodes.safe_push (noreorder[noreorder_pos++]);
  184.    add_sorted_nodes (next_nodes, partition);
  185. -
  186.    free (order);
  187.  
  188.    if (symtab->dump_file)
Add Comment
Please, Sign In to add comment