mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-27 14:24:40 +00:00
Add profile writing capabilities for sampling profiles.
Summary: This patch finishes up support for handling sampling profiles in both text and binary formats. The new binary format uses uleb128 encoding to represent numeric values. This makes profiles files about 25% smaller. The profile writer class can write profiles in the existing text and the new binary format. In subsequent patches, I will add the capability to read (and perhaps write) profiles in the gcov format used by GCC. Additionally, I will be adding support in llvm-profdata to manipulate sampling profiles. There was a bit of refactoring needed to separate some code that was in the reader files, but is actually common to both the reader and writer. The new test checks that reading the same profile encoded as text or raw, produces the same results. Reviewers: bogner, dexonsmith Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6000 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220915 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
82
include/llvm/ProfileData/SampleProfWriter.h
Normal file
82
include/llvm/ProfileData/SampleProfWriter.h
Normal file
@ -0,0 +1,82 @@
|
||||
//===- SampleProfWriter.h - Write LLVM sample profile data ----------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file contains definitions needed for writing sample profiles.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#ifndef LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
|
||||
#define LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/ProfileData/SampleProf.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
namespace sampleprof {
|
||||
|
||||
/// \brief Sample-based profile writer. Base class.
|
||||
class SampleProfileWriter {
|
||||
public:
|
||||
SampleProfileWriter(StringRef Filename, std::error_code &EC,
|
||||
sys::fs::OpenFlags Flags)
|
||||
: OS(Filename, EC, Flags) {}
|
||||
virtual ~SampleProfileWriter() {}
|
||||
|
||||
/// \brief Write sample profiles in \p S for function \p F.
|
||||
///
|
||||
/// \returns true if the file was updated successfully. False, otherwise.
|
||||
virtual bool write(const Function &F, const FunctionSamples &S) = 0;
|
||||
|
||||
/// \brief Write all the sample profiles for all the functions in \p M.
|
||||
///
|
||||
/// \returns true if the file was updated successfully. False, otherwise.
|
||||
bool write(const Module &M, StringMap<FunctionSamples> &P) {
|
||||
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||
if (!write((*I), P[I->getName()]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// \brief Output stream where to emit the profile to.
|
||||
raw_fd_ostream OS;
|
||||
};
|
||||
|
||||
/// \brief Sample-based profile writer (text format).
|
||||
class SampleProfileWriterText : public SampleProfileWriter {
|
||||
public:
|
||||
SampleProfileWriterText(StringRef F, std::error_code &EC)
|
||||
: SampleProfileWriter(F, EC, sys::fs::F_Text) {}
|
||||
|
||||
bool write(const Function &F, const FunctionSamples &S) override;
|
||||
bool write(const Module &M, StringMap<FunctionSamples> &P) {
|
||||
return SampleProfileWriter::write(M, P);
|
||||
}
|
||||
};
|
||||
|
||||
/// \brief Sample-based profile writer (binary format).
|
||||
class SampleProfileWriterBinary : public SampleProfileWriter {
|
||||
public:
|
||||
SampleProfileWriterBinary(StringRef F, std::error_code &EC);
|
||||
|
||||
bool write(const Function &F, const FunctionSamples &S) override;
|
||||
bool write(const Module &M, StringMap<FunctionSamples> &P) {
|
||||
return SampleProfileWriter::write(M, P);
|
||||
}
|
||||
};
|
||||
|
||||
} // End namespace sampleprof
|
||||
|
||||
} // End namespace sampleprof
|
||||
|
||||
#endif // LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
|
Reference in New Issue
Block a user