29 #define DEBUG_TYPE "cfgmst"
35 template <
class Edge,
class BBInfo>
class CFGMST {
50 return static_cast<BBInfo *
>(G->Group);
63 if (BB1G->Rank < BB2G->Rank)
68 if (BB1G->Rank == BB2G->Rank)
77 assert(It->second.get() !=
nullptr);
78 return *It->second.get();
86 return It->second.get();
98 addEdge(
nullptr, BB, EntryWeight);
102 addEdge(BB,
nullptr, EntryWeight);
106 static const uint32_t CriticalEdgeMultiplier = 1000;
117 uint64_t scaleFactor = BBWeight;
119 if (scaleFactor < UINT64_MAX / CriticalEdgeMultiplier)
120 scaleFactor *= CriticalEdgeMultiplier;
122 scaleFactor = UINT64_MAX;
126 addEdge(&*BB, TargetBB, Weight).IsCritical = Critical;
127 DEBUG(
dbgs() <<
" Edge: from " << BB->getName() <<
" to "
128 << TargetBB->
getName() <<
" w=" << Weight <<
"\n");
131 addEdge(&*BB,
nullptr, BBWeight);
132 DEBUG(
dbgs() <<
" Edge: from " << BB->getName() <<
" to exit"
133 <<
" w = " << BBWeight <<
"\n");
141 [](
const std::unique_ptr<Edge> &Edge1,
142 const std::unique_ptr<Edge> &Edge2) {
143 return Edge1->Weight > Edge2->Weight;
156 if (Ei->IsCritical) {
157 if (Ei->DestBB && Ei->DestBB->isLandingPad()) {
164 for (
auto &Ei : AllEdges) {
174 if (!Message.
str().empty())
175 OS << Message <<
"\n";
176 OS <<
" Number of Basic Blocks: " <<
BBInfos.size() <<
"\n";
179 OS <<
" BB: " << (BB ==
nullptr ?
"FakeNode" : BB->
getName()) <<
" "
180 << BI.second->infoString() <<
"\n";
183 OS <<
" Number of Edges: " <<
AllEdges.size()
184 <<
" (*: Instrument, C: CriticalEdge, -: Removed)\n";
187 OS <<
" Edge " << Count++ <<
": " <<
getBBInfo(EI->SrcBB).Index <<
"-->"
188 <<
getBBInfo(EI->DestBB).Index << EI->infoString() <<
"\n";
196 std::tie(Iter, Inserted) =
BBInfos.insert(std::make_pair(Src,
nullptr));
199 Iter->second = std::move(llvm::make_unique<BBInfo>(Index));
202 std::tie(Iter, Inserted) =
BBInfos.insert(std::make_pair(Dest,
nullptr));
205 Iter->second = std::move(llvm::make_unique<BBInfo>(Index));
206 AllEdges.emplace_back(
new Edge(Src, Dest, W));
216 :
F(Func),
BPI(BPI_),
BFI(BFI_) {
223 #undef DEBUG_TYPE // "cfgmst"
std::vector< std::unique_ptr< Edge > > AllEdges
CFGMST(Function &Func, BranchProbabilityInfo *BPI_=nullptr, BlockFrequencyInfo *BFI_=nullptr)
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
An union-find based Minimum Spanning Tree for CFG.
StringRef getName() const
Return a constant reference to the value's name.
std::string str() const
Return the twine contents as a std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
BBInfo & getBBInfo(const BasicBlock *BB) const
bool unionGroups(const BasicBlock *BB1, const BasicBlock *BB2)
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Subclasses of this class are all able to terminate a basic block.
LLVM Basic Block Representation.
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
bool succ_empty(const BasicBlock *BB)
uint64_t getEntryFreq() const
DenseMap< const BasicBlock *, std::unique_ptr< BBInfo > > BBInfos
BBInfo * findBBInfo(const BasicBlock *BB) const
void computeMinimumSpanningTree()
Iterator for intrusive lists based on ilist_node.
void dumpEdges(raw_ostream &OS, const Twine &Message) const
BBInfo * findAndCompressGroup(BBInfo *G)
const BasicBlock & getEntryBlock() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
BranchProbabilityInfo * BPI
Analysis providing branch probability information.
uint64_t scale(uint64_t Num) const
Scale a large integer.
Edge & addEdge(const BasicBlock *Src, const BasicBlock *Dest, uint64_t W)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
succ_range successors(BasicBlock *BB)
This class implements an extremely fast bulk output stream that can only output to a stream...
BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum, bool AllowIdenticalEdges=false)
Return true if the specified edge is a critical edge.