Switch to using edge profiling information as the basic source of profile info
from using basic block counts.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12242 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/ProfileInfoLoaderPass.cpp b/lib/Analysis/ProfileInfoLoaderPass.cpp
index c1ff8cf..b32dcc4 100644
--- a/lib/Analysis/ProfileInfoLoaderPass.cpp
+++ b/lib/Analysis/ProfileInfoLoaderPass.cpp
@@ -12,6 +12,8 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/BasicBlock.h"
+#include "llvm/InstrTypes.h"
#include "llvm/Pass.h"
#include "llvm/Analysis/ProfileInfo.h"
#include "llvm/Analysis/ProfileInfoLoader.h"
@@ -60,11 +62,25 @@
bool LoaderPass::run(Module &M) {
ProfileInfoLoader PIL("profile-loader", Filename, M);
- ExecutionCounts.clear();
- if (PIL.hasAccurateBlockCounts()) {
- std::vector<std::pair<BasicBlock*, unsigned> > Counts;
- PIL.getBlockCounts(Counts);
- ExecutionCounts.insert(Counts.begin(), Counts.end());
+ EdgeCounts.clear();
+ bool PrintedWarning = false;
+
+ std::vector<std::pair<ProfileInfoLoader::Edge, unsigned> > ECs;
+ PIL.getEdgeCounts(ECs);
+ for (unsigned i = 0, e = ECs.size(); i != e; ++i) {
+ BasicBlock *BB = ECs[i].first.first;
+ unsigned SuccNum = ECs[i].first.second;
+ TerminatorInst *TI = BB->getTerminator();
+ if (SuccNum >= TI->getNumSuccessors()) {
+ if (!PrintedWarning) {
+ std::cerr << "WARNING: profile information is inconsistent with "
+ << "the current program!\n";
+ PrintedWarning = true;
+ }
+ } else {
+ EdgeCounts[std::make_pair(BB, TI->getSuccessor(SuccNum))]+= ECs[i].second;
+ }
}
+
return false;
}