//
//===----------------------------------------------------------------------===//
-#include "llvm/InstrTypes.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Module.h"
-#include "llvm/PassManager.h"
-#include "llvm/Assembly/AssemblyAnnotationWriter.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/ProfileInfo.h"
#include "llvm/Analysis/ProfileInfoLoader.h"
-#include "llvm/Analysis/Passes.h"
+#include "llvm/Assembly/AssemblyAnnotationWriter.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Module.h"
+#include "llvm/PassManager.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Format.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/Format.h"
#include "llvm/Support/Signals.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/system_error.h"
#include <algorithm>
#include <iomanip>
ProfileInfoLoader &PIL;
public:
static char ID; // Class identification, replacement for typeinfo.
- explicit ProfileInfoPrinterPass(ProfileInfoLoader &_PIL)
+ explicit ProfileInfoPrinterPass(ProfileInfoLoader &_PIL)
: ModulePass(ID), PIL(_PIL) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
bool ProfileInfoPrinterPass::runOnModule(Module &M) {
ProfileInfo &PI = getAnalysis<ProfileInfo>();
- std::map<const Function *, unsigned> FuncFreqs;
- std::map<const BasicBlock*, unsigned> BlockFreqs;
- std::map<ProfileInfo::Edge, unsigned> EdgeFreqs;
// Output a report. Eventually, there will be multiple reports selectable on
// the command line, for now, just keep things simple.
if (FI->isDeclaration()) continue;
double w = ignoreMissing(PI.getExecutionCount(FI));
FunctionCounts.push_back(std::make_pair(FI, w));
- for (Function::iterator BB = FI->begin(), BBE = FI->end();
+ for (Function::iterator BB = FI->begin(), BBE = FI->end();
BB != BBE; ++BB) {
double w = ignoreMissing(PI.getExecutionCount(BB));
Counts.push_back(std::make_pair(BB, w));
outs() << " ## Frequency\n";
for (unsigned i = 0, e = FunctionCounts.size(); i != e; ++i) {
if (FunctionCounts[i].second == 0) {
- outs() << "\n NOTE: " << e-i << " function"
+ outs() << "\n NOTE: " << e-i << " function"
<< (e-i-1 ? "s were" : " was") << " never executed!\n";
break;
}
TotalExecutions = 0;
for (unsigned i = 0, e = Counts.size(); i != e; ++i)
TotalExecutions += Counts[i].second;
-
+
// Sort by the frequency, backwards.
sort(Counts.begin(), Counts.end(),
PairSecondSortReverse<BasicBlock*>());
-
+
outs() << "\n===" << std::string(73, '-') << "===\n";
outs() << "Top 20 most frequently executed basic blocks:\n\n";
-
+
// Print out the function frequencies...
outs() <<" ## %% \tFrequency\n";
unsigned BlocksToPrint = Counts.size();
if (PrintAnnotatedLLVM || PrintAllCode) {
outs() << "\n===" << std::string(73, '-') << "===\n";
outs() << "Annotated LLVM code for the module:\n\n";
-
+
ProfileAnnotator PA(PI);
if (FunctionsToPrint.empty() || PrintAllCode)
LLVMContext &Context = getGlobalContext();
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
-
+
cl::ParseCommandLineOptions(argc, argv, "llvm profile dump decoder\n");
// Read in the bitcode file...
PassManager PassMgr;
PassMgr.add(createProfileLoaderPass(ProfileDataFile));
PassMgr.add(new ProfileInfoPrinterPass(PIL));
- PassMgr.doInitialization();
PassMgr.run(*M);
- PassMgr.doFinalization();
return 0;
}