Index: ELF/CallGraphSort.cpp =================================================================== --- ELF/CallGraphSort.cpp +++ ELF/CallGraphSort.cpp @@ -66,6 +66,7 @@ std::vector Sections; size_t Size = 0; uint64_t Weight = 0; + uint64_t InitialWeight = 0; std::vector Preds; std::vector Succs; }; @@ -74,17 +75,16 @@ int From; int To; uint64_t Weight; - double NormalizedWeight; }; struct EdgeDenseMapInfo { static Edge getEmptyKey() { return {DenseMapInfo::getEmptyKey(), DenseMapInfo::getEmptyKey(), - 0, 0}; + 0}; } static Edge getTombstoneKey() { return {DenseMapInfo::getTombstoneKey(), - DenseMapInfo::getTombstoneKey(), 0, 0}; + DenseMapInfo::getTombstoneKey(), 0}; } static unsigned getHashValue(const Edge &Val) { return hash_combine(DenseMapInfo::getHashValue(Val.From), @@ -107,7 +107,6 @@ std::vector Edges; std::vector Sections; - void normalizeEdgeWeights(); void groupClusters(); }; @@ -117,9 +116,6 @@ // Maximum cluster size in bytes. constexpr uint64_t MAX_CLUSTER_SIZE = 1024 * 1024; - -// Minimum edge probability to consider merging. -constexpr double MIN_EDGE_PROBABILITY = 0.1; } // end anonymous namespace // Take the edge list in Config->CallGraphProfile, resolve symbol names to @@ -178,7 +174,7 @@ if (From == To) continue; - Edge E{From, To, Weight, 0}; + Edge E{From, To, Weight}; // Add or increment an edge auto Res = EdgeMap.insert(std::make_pair(E, Edges.size())); @@ -190,21 +186,9 @@ } else Edges[EI].Weight += Weight; } - normalizeEdgeWeights(); -} -// Normalize the edge weights so that we can reject edges which have a low -// probibility. -void CallGraphSort::normalizeEdgeWeights() { - for (int SI = 0, SE = Sections.size(); SI != SE; ++SI) { - Cluster &C = Clusters[SI]; - for (int PI : C.Preds) { - Edge &E = Edges[EdgeMap[{PI, SI, 0, 0}]]; - if (C.Weight == 0) - continue; - E.NormalizedWeight = double(E.Weight) / double(C.Weight); - } - } + for (Cluster &C : Clusters) + C.InitialWeight = C.Weight; } // It's bad to merge clusters which would degrade the density too much. @@ -244,17 +228,18 @@ Cluster &C = *SecToCluster[SI]; int BestPred = -1; - double BestWeight = 0; + uint64_t BestWeight = 0; for (int PI : Clusters[SI].Preds) { - Edge &E = Edges[EdgeMap[{PI, SI, 0, 0}]]; - if (BestPred == -1 || E.NormalizedWeight > BestWeight) { + Edge &E = Edges[EdgeMap[{PI, SI, 0}]]; + if (BestPred == -1 || E.Weight > BestWeight) { BestPred = PI; - BestWeight = E.NormalizedWeight; + BestWeight = E.Weight; } } - if (BestWeight < MIN_EDGE_PROBABILITY) + // don't consider merging if the edge is unlikely. + if (BestWeight * 10 <= C.InitialWeight) continue; Cluster *PredC = SecToCluster[BestPred];