15 #ifndef LLVM_ANALYSIS_MAXIMUMSPANNINGTREE_H
16 #define LLVM_ANALYSIS_MAXIMUMSPANNINGTREE_H
30 typedef std::pair<const T*, const T*>
Edge;
40 struct EdgeWeightCompare {
41 static bool getBlockSize(
const T *
X) {
42 const BasicBlock *BB = dyn_cast_or_null<BasicBlock>(
X);
43 return BB ? BB->
size() : 0;
47 if (X.second > Y.second)
return true;
48 if (X.second < Y.second)
return false;
51 size_t XSizeA = getBlockSize(X.first.first);
52 size_t YSizeA = getBlockSize(Y.first.first);
53 if (XSizeA > YSizeA)
return true;
54 if (XSizeA < YSizeA)
return false;
56 size_t XSizeB = getBlockSize(X.first.second);
57 size_t YSizeB = getBlockSize(Y.first.second);
58 if (XSizeB > YSizeB)
return true;
59 if (XSizeB < YSizeB)
return false;
72 std::stable_sort(EdgeVector.begin(), EdgeVector.end(), EdgeWeightCompare());
78 for (
typename EdgeWeights::iterator EWi = EdgeVector.begin(),
79 EWe = EdgeVector.end(); EWi != EWe; ++EWi) {
80 Edge e = (*EWi).first;
83 Forest.insert(e.second);
87 for (
typename EdgeWeights::iterator EWi = EdgeVector.begin(),
88 EWe = EdgeVector.end(); EWi != EWe; ++EWi) {
89 Edge e = (*EWi).first;
91 if (Forest.findLeader(e.first) != Forest.findLeader(e.second)) {
92 Forest.unionSets(e.first, e.second);
100 typename MaxSpanTree::iterator
begin() {
104 typename MaxSpanTree::iterator
end() {
std::vector< Edge > MaxSpanTree
std::pair< const T *, const T * > Edge
MaximumSpanningTree - A MST implementation.
iterator insert(const ElemTy &Data)
insert - Insert a new value into the union/find set, ignoring the request if the value already exists...
MaxSpanTree::iterator end()
MaxSpanTree::iterator begin()
LLVM Basic Block Representation.
EquivalenceClasses - This represents a collection of equivalence classes and supports three efficient...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
MaximumSpanningTree(EdgeWeights &EdgeVector)
MaximumSpanningTree() - Takes a vector of weighted edges and returns a spanning tree.
std::pair< Edge, double > EdgeWeight
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
std::vector< EdgeWeight > EdgeWeights