15 #ifndef LLVM_LIB_TRANSFORMS_INSTRUMENTATION_CFGMST_H
16 #define LLVM_LIB_TRANSFORMS_INSTRUMENTATION_CFGMST_H
30 #define DEBUG_TYPE "cfgmst"
38 template <
class Edge,
class BBInfo>
class CFGMST {
53 return static_cast<BBInfo *
>(G->Group);
66 if (BB1G->Rank < BB2G->Rank)
71 if (BB1G->Rank == BB2G->Rank)
80 assert(It->second.get() !=
nullptr);
81 return *It->second.get();
89 return It->second.get();
101 addEdge(
nullptr, BB, EntryWeight);
105 addEdge(BB,
nullptr, EntryWeight);
109 static const uint32_t CriticalEdgeMultiplier = 1000;
120 uint64_t scaleFactor = BBWeight;
122 if (scaleFactor < UINT64_MAX / CriticalEdgeMultiplier)
123 scaleFactor *= CriticalEdgeMultiplier;
125 scaleFactor = UINT64_MAX;
129 addEdge(&*BB, TargetBB, Weight).IsCritical = Critical;
130 DEBUG(
dbgs() <<
" Edge: from " << BB->getName() <<
" to "
131 << TargetBB->
getName() <<
" w=" << Weight <<
"\n");
134 addEdge(&*BB,
nullptr, BBWeight);
135 DEBUG(
dbgs() <<
" Edge: from " << BB->getName() <<
" to exit"
136 <<
" w = " << BBWeight <<
"\n");
144 [](
const std::unique_ptr<Edge> &Edge1,
145 const std::unique_ptr<Edge> &Edge2) {
146 return Edge1->Weight > Edge2->Weight;
159 if (Ei->IsCritical) {
160 if (Ei->DestBB && Ei->DestBB->isLandingPad()) {
167 for (
auto &Ei : AllEdges) {
177 if (!Message.
str().empty())
178 OS << Message <<
"\n";
179 OS <<
" Number of Basic Blocks: " <<
BBInfos.size() <<
"\n";
182 OS <<
" BB: " << (BB ==
nullptr ?
"FakeNode" : BB->
getName()) <<
" "
183 << BI.second->infoString() <<
"\n";
186 OS <<
" Number of Edges: " <<
AllEdges.size()
187 <<
" (*: Instrument, C: CriticalEdge, -: Removed)\n";
190 OS <<
" Edge " << Count++ <<
": " <<
getBBInfo(EI->SrcBB).Index <<
"-->"
191 <<
getBBInfo(EI->DestBB).Index << EI->infoString() <<
"\n";
199 std::tie(Iter, Inserted) =
BBInfos.insert(std::make_pair(Src,
nullptr));
202 Iter->second = std::move(llvm::make_unique<BBInfo>(Index));
205 std::tie(Iter, Inserted) =
BBInfos.insert(std::make_pair(Dest,
nullptr));
208 Iter->second = std::move(llvm::make_unique<BBInfo>(Index));
209 AllEdges.emplace_back(
new Edge(Src, Dest, W));
219 :
F(Func),
BPI(BPI_),
BFI(BFI_) {
228 #undef DEBUG_TYPE // "cfgmst"
230 #endif // LLVM_LIB_TRANSFORMS_INSTRUMENTATION_CFGMST_H
std::vector< std::unique_ptr< Edge > > AllEdges
CFGMST(Function &Func, BranchProbabilityInfo *BPI_=nullptr, BlockFrequencyInfo *BFI_=nullptr)
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
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)
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.
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
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
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.