Add show and merge tools for sample PGO profiles.

Summary:
This patch extends the 'show' and 'merge' commands in llvm-profdata to handle
sample PGO formats. Using the 'merge' command it is now possible to convert
one sample PGO format to another.

The only format that is currently not working is 'gcc'. I still need to
implement support for it in lib/ProfileData.

The changes in the sample profile support classes are needed for the
merge operation.

Reviewers: bogner

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D6065

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221032 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Diego Novillo
2014-11-01 00:56:55 +00:00
parent e542d91ee5
commit 9657de5f22
9 changed files with 323 additions and 123 deletions

View File

@@ -21,6 +21,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ProfileData/SampleProf.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -64,9 +65,6 @@ public:
virtual ~SampleProfileReader() {}
/// \brief Print all the profiles to dbgs().
void dump();
/// \brief Read and validate the file header.
virtual std::error_code readHeader() = 0;
@@ -74,16 +72,19 @@ public:
virtual std::error_code read() = 0;
/// \brief Print the profile for \p FName on stream \p OS.
void printFunctionProfile(raw_ostream &OS, StringRef FName);
void dumpFunctionProfile(StringRef FName, raw_ostream &OS = dbgs());
/// \brief Print the profile for \p FName on dbgs().
void dumpFunctionProfile(StringRef FName);
/// \brief Print all the profiles on stream \p OS.
void dump(raw_ostream &OS = dbgs());
/// \brief Return the samples collected for function \p F.
FunctionSamples *getSamplesFor(const Function &F) {
return &Profiles[F.getName()];
}
/// \brief Return all the profiles.
StringMap<FunctionSamples> &getProfiles() { return Profiles; }
/// \brief Report a parse error message.
void reportParseError(int64_t LineNumber, Twine Msg) const {
Ctx.diagnose(DiagnosticInfoSampleProfile(Buffer->getBufferIdentifier(),
@@ -91,7 +92,7 @@ public:
}
/// \brief Create a sample profile reader appropriate to the file format.
static std::error_code create(std::string Filename,
static std::error_code create(StringRef Filename,
std::unique_ptr<SampleProfileReader> &Reader,
LLVMContext &C);