本文整理汇总了C++中ProfileData::getEdgeWeight方法的典型用法代码示例。如果您正苦于以下问题:C++ ProfileData::getEdgeWeight方法的具体用法?C++ ProfileData::getEdgeWeight怎么用?C++ ProfileData::getEdgeWeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProfileData
的用法示例。
在下文中一共展示了ProfileData::getEdgeWeight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readEdge
/// readEdge - Take the value from a profile counter and assign it to an edge.
void ProfileMetadataLoaderPass::readEdge(unsigned ReadCount,
ProfileData &PB, ProfileData::Edge e,
ArrayRef<unsigned> Counters) {
if (ReadCount >= Counters.size()) return;
unsigned weight = Counters[ReadCount];
assert(weight != ProfileDataLoader::Uncounted);
PB.addEdgeWeight(e, weight);
DEBUG(dbgs() << "-- Read Edge Counter for " << e
<< " (# "<< (ReadCount) << "): "
<< PB.getEdgeWeight(e) << "\n");
}
示例2: setBranchWeightMetadata
/// setBranchWeightMetadata - Translate the counter values associated with each
/// edge into branch weights for each conditional branch (a branch with 2 or
/// more desinations).
void ProfileMetadataLoaderPass::setBranchWeightMetadata(Module &M,
ProfileData &PB) {
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
if (F->isDeclaration()) continue;
DEBUG(dbgs() << "Setting branch metadata in '" << F->getName() << "'\n");
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
TerminatorInst *TI = BB->getTerminator();
unsigned NumSuccessors = TI->getNumSuccessors();
// If there is only one successor then we can not set a branch
// probability as the target is certain.
if (NumSuccessors < 2) continue;
// Load the weights of all edges leading from this terminator.
DEBUG(dbgs() << "-- Terminator with " << NumSuccessors
<< " successors:\n");
SmallVector<uint32_t, 4> Weights(NumSuccessors);
for (unsigned s = 0 ; s < NumSuccessors ; ++s) {
ProfileData::Edge edge = PB.getEdge(BB, TI->getSuccessor(s));
Weights[s] = (uint32_t)PB.getEdgeWeight(edge);
DEBUG(dbgs() << "---- Edge '" << edge << "' has weight "
<< Weights[s] << "\n");
}
// Set branch weight metadata. This will set branch probabilities of
// 100%/0% if that is true of the dynamic execution.
// BranchProbabilityInfo can account for this when it loads this metadata
// (it gives the unexectuted branch a weight of 1 for the purposes of
// probability calculations).
MDBuilder MDB(TI->getContext());
MDNode *Node = MDB.createBranchWeights(Weights);
TI->setMetadata(LLVMContext::MD_prof, Node);
NumTermsAnnotated++;
}
}
}