Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c
- index 9eb63c2..6ae3dd8 100644
- --- a/gcc/lto/lto-partition.c
- +++ b/gcc/lto/lto-partition.c
- @@ -34,6 +34,10 @@ along with GCC; see the file COPYING3. If not see
- #include "ipa-prop.h"
- #include "ipa-inline.h"
- #include "lto-partition.h"
- +#include <map>
- +#include <set>
- +#include <vector>
- +#include <algorithm>
- vec<ltrans_partition> ltrans_partitions;
- @@ -446,6 +450,23 @@ add_sorted_nodes (vec<symtab_node *> &next_nodes, ltrans_partition partition)
- the process is undone to the point where the minimal ratio of boundary size
- and in-partition calls was reached. */
- +struct var_ref
- +{
- + int nrefs;
- + int partition_index;
- +};
- +
- +typedef std::map< std::set<varpool_node *>, var_ref > vars_map_t;
- +typedef std::pair< std::set<varpool_node *>, var_ref > vars_pair;
- +typedef std::map< std::set<varpool_node *>, var_ref >::iterator vars_map_iter;
- +
- +/* Compare in non-increasing order. */
- +bool
- +cmp_var_ref (const vars_pair& a, const vars_pair& b)
- +{
- + return a.second.nrefs > b.second.nrefs;
- +}
- +
- void
- lto_balanced_map (int n_lto_partitions)
- {
- @@ -468,6 +489,8 @@ lto_balanced_map (int n_lto_partitions)
- int current_order = -1;
- int noreorder_pos = 0;
- + symtab->dump_file = stderr;
- +
- FOR_EACH_VARIABLE (vnode)
- gcc_assert (!vnode->aux);
- @@ -719,7 +742,7 @@ lto_balanced_map (int n_lto_partitions)
- best_cost, best_internal, best_i);
- /* Partition is too large, unwind into step when best cost was reached and
- start new partition. */
- - if (partition->insns > 2 * partition_size)
- + if (partition->insns > 2 * partition_size || 1)
- {
- if (best_i != i)
- {
- @@ -758,6 +781,122 @@ lto_balanced_map (int n_lto_partitions)
- }
- }
- + vars_map_t vars_map;
- +
- + std::map< std::set<varpool_node *>, int > partition_map;
- + typedef std::map<std::set<varpool_node *>, int>::iterator partition_map_iter;
- +
- + for (unsigned i = 0; i < ltrans_partitions.length (); ++i)
- + {
- + ltrans_partition part = ltrans_partitions[i];
- +
- + for (int j = 0; j < lto_symtab_encoder_size (part->encoder); j++)
- + {
- + symtab_node *snode = lto_symtab_encoder_deref (part->encoder, j);
- + if (cgraph_node *cnode = dyn_cast<cgraph_node *> (snode))
- + {
- + fprintf (stderr, "function %s is in partition %d\n", cnode->name (), i);
- + ipa_ref *ref;
- + std::set<varpool_node *> var_set;
- +
- + for (int k = 0; cnode->iterate_reference (k, ref); k++)
- + {
- + varpool_node *vnode = dyn_cast<varpool_node *> (ref->referred);
- + if (vnode
- +// && vnode->get_partitioning_class () == SYMBOL_PARTITION
- +// && !symbol_partitioned_p (vnode)
- + && !vnode->no_reorder)
- + var_set.insert (vnode);
- + }
- + if (var_set.size () >= 2)
- + partition_map[var_set]++;
- +
- + var_set.clear ();
- + }
- + }
- +
- + for (partition_map_iter p_it = partition_map.begin (); p_it != partition_map.end (); ++p_it)
- + {
- + const std::set<varpool_node *>& var_set = p_it->first;
- + int nrefs = p_it->second;
- +
- + struct var_ref& vr = vars_map[var_set];
- + if (vr.nrefs < nrefs)
- + {
- + vr.nrefs = nrefs;
- + vr.partition_index = i;
- + }
- + }
- + }
- +
- +#if 1
- + fprintf (stderr, "\nvars_map: \n");
- + for (vars_map_iter it = vars_map.begin (); it != vars_map.end (); ++it)
- + {
- + const std::set<varpool_node *>& var_set = it->first;
- + struct var_ref vr = it->second;
- +
- + fprintf (stderr, "{");
- + for (std::set<varpool_node *>::const_iterator set_it = var_set.begin (); set_it != var_set.end (); ++set_it)
- + {
- + varpool_node *vnode = *set_it;
- + fprintf (stderr, "%s, ", vnode->name ());
- + }
- + fprintf (stderr, "} -> %d, %d\n", vr.nrefs, vr.partition_index);
- + }
- +#endif
- +
- + std::vector<vars_pair> vec_vr;
- +
- + for (vars_map_iter it = vars_map.begin (); it != vars_map.end (); ++it)
- + vec_vr.push_back (*it);
- +
- + std::sort (vec_vr.begin (), vec_vr.end (), cmp_var_ref);
- +
- +#if 1
- + fprintf (stderr, "\nvars_map in non increasing order:\n");
- + for (std::vector<vars_pair>::iterator it = vec_vr.begin (); it != vec_vr.end (); ++it)
- + {
- + const std::set<varpool_node *>& var_set = it->first;
- + struct var_ref vr = it->second;
- +
- + fprintf (stderr, "{");
- + for (std::set<varpool_node *>::const_iterator set_it = var_set.begin (); set_it != var_set.end (); ++set_it)
- + {
- + varpool_node *vnode = *set_it;
- + fprintf (stderr, "%s, ", vnode->name ());
- + }
- + fprintf (stderr, "} -> %d, %d\n", vr.nrefs, vr.partition_index);
- + }
- +#endif
- +
- + for (std::vector<vars_pair>::iterator it = vec_vr.begin (); it != vec_vr.end (); ++it)
- + {
- + const std::set<varpool_node *>& var_set = it->first;
- + struct var_ref vr = it->second;
- +
- + std::vector<varpool_node *> out;
- + out.clear ();
- +
- + for (std::set<varpool_node *>::iterator set_it = var_set.begin (); set_it != var_set.end (); ++set_it)
- + {
- + varpool_node *vnode = *set_it;
- +// if (!symbol_partitioned_p (vnode) && vnode->get_partitioning_class () == SYMBOL_PARTITION)
- + out.push_back (vnode);
- + }
- +
- + if (out.size () >= 2)
- + {
- + for (std::vector<varpool_node *>::iterator it = out.begin (); it != out.end (); ++it)
- + {
- + varpool_node *vnode = *it;
- + fprintf (stderr, "%s goes to partition %d\n", vnode->name (), vr.partition_index);
- +// if (!symbol_partitioned_p (vnode))
- +// add_symbol_to_partition (ltrans_partitions[vr.partition_index], vnode);
- + }
- + }
- + }
- +
- next_nodes.truncate (0);
- /* Varables that are not reachable from the code go into last partition. */
- @@ -776,7 +915,6 @@ lto_balanced_map (int n_lto_partitions)
- while (noreorder_pos < (int)noreorder.length ())
- next_nodes.safe_push (noreorder[noreorder_pos++]);
- add_sorted_nodes (next_nodes, partition);
- -
- free (order);
- if (symtab->dump_file)
Add Comment
Please, Sign In to add comment