2004-02-11 06:10:05 +00:00
|
|
|
//===- ProfileInfoLoaderPass.cpp - LLVM Pass to load profile info ---------===//
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2004-02-11 06:10:05 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2004-02-11 06:10:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements a concrete implementation of profiling information that
|
|
|
|
// loads the information from a profile dump file.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-03-08 22:04:08 +00:00
|
|
|
#include "llvm/BasicBlock.h"
|
|
|
|
#include "llvm/InstrTypes.h"
|
2004-02-11 06:10:05 +00:00
|
|
|
#include "llvm/Pass.h"
|
2005-01-08 22:01:16 +00:00
|
|
|
#include "llvm/Analysis/Passes.h"
|
2004-02-11 06:10:05 +00:00
|
|
|
#include "llvm/Analysis/ProfileInfo.h"
|
|
|
|
#include "llvm/Analysis/ProfileInfoLoader.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2007-02-05 23:42:17 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2006-11-28 22:46:12 +00:00
|
|
|
#include "llvm/Support/Streams.h"
|
2004-02-11 06:10:05 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
2004-02-11 18:21:05 +00:00
|
|
|
cl::opt<std::string>
|
|
|
|
ProfileInfoFilename("profile-info-file", cl::init("llvmprof.out"),
|
2004-02-11 19:14:04 +00:00
|
|
|
cl::value_desc("filename"),
|
|
|
|
cl::desc("Profile file loaded by -profile-loader"));
|
2004-02-11 18:21:05 +00:00
|
|
|
|
2007-02-05 23:42:17 +00:00
|
|
|
class VISIBILITY_HIDDEN LoaderPass : public ModulePass, public ProfileInfo {
|
2004-02-11 06:10:05 +00:00
|
|
|
std::string Filename;
|
|
|
|
public:
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID; // Class identification, replacement for typeinfo
|
2007-08-01 15:32:29 +00:00
|
|
|
explicit LoaderPass(const std::string &filename = "")
|
2008-03-19 21:56:59 +00:00
|
|
|
: ModulePass((intptr_t)&ID), Filename(filename) {
|
2004-02-11 18:21:05 +00:00
|
|
|
if (filename.empty()) Filename = ProfileInfoFilename;
|
|
|
|
}
|
2004-02-11 06:10:05 +00:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "Profiling information loader";
|
|
|
|
}
|
|
|
|
|
|
|
|
/// run - Load the profile information from the specified file.
|
2004-09-20 04:48:05 +00:00
|
|
|
virtual bool runOnModule(Module &M);
|
2004-02-11 06:10:05 +00:00
|
|
|
};
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2007-05-03 01:11:54 +00:00
|
|
|
char LoaderPass::ID = 0;
|
2006-08-27 22:42:52 +00:00
|
|
|
RegisterPass<LoaderPass>
|
2008-03-19 21:56:59 +00:00
|
|
|
X("profile-loader", "Load profile information from llvmprof.out", true, true);
|
2004-02-11 06:10:05 +00:00
|
|
|
|
2006-08-28 00:42:29 +00:00
|
|
|
RegisterAnalysisGroup<ProfileInfo> Y(X);
|
2004-02-11 06:10:05 +00:00
|
|
|
} // End of anonymous namespace
|
|
|
|
|
2005-01-10 03:56:27 +00:00
|
|
|
ModulePass *llvm::createProfileLoaderPass() { return new LoaderPass(); }
|
2004-02-11 06:10:05 +00:00
|
|
|
|
|
|
|
/// createProfileLoaderPass - This function returns a Pass that loads the
|
|
|
|
/// profiling information for the module from the specified filename, making it
|
|
|
|
/// available to the optimizers.
|
|
|
|
Pass *llvm::createProfileLoaderPass(const std::string &Filename) {
|
|
|
|
return new LoaderPass(Filename);
|
|
|
|
}
|
|
|
|
|
2004-09-20 04:48:05 +00:00
|
|
|
bool LoaderPass::runOnModule(Module &M) {
|
2004-03-08 21:30:35 +00:00
|
|
|
ProfileInfoLoader PIL("profile-loader", Filename, M);
|
2004-03-08 22:04:08 +00:00
|
|
|
EdgeCounts.clear();
|
|
|
|
bool PrintedWarning = false;
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2004-03-08 22:04:08 +00:00
|
|
|
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) {
|
2006-12-07 01:30:32 +00:00
|
|
|
cerr << "WARNING: profile information is inconsistent with "
|
|
|
|
<< "the current program!\n";
|
2004-03-08 22:04:08 +00:00
|
|
|
PrintedWarning = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
EdgeCounts[std::make_pair(BB, TI->getSuccessor(SuccNum))]+= ECs[i].second;
|
|
|
|
}
|
2004-02-11 18:21:05 +00:00
|
|
|
}
|
2004-03-08 22:04:08 +00:00
|
|
|
|
2004-02-11 06:10:05 +00:00
|
|
|
return false;
|
|
|
|
}
|