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
iterator insert(const ElemTy &Data)
MaxSpanTree::iterator end()
MaxSpanTree::iterator begin()
LLVM Basic Block Representation.
MaximumSpanningTree(EdgeWeights &EdgeVector)
std::pair< Edge, double > EdgeWeight
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
std::vector< EdgeWeight > EdgeWeights