2014-10-30 19:00:06 +01:00
|
|
|
//===- 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"
|
2014-11-03 01:51:45 +01:00
|
|
|
#include "llvm/Support/ErrorOr.h"
|
2014-10-30 19:00:06 +01:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
namespace sampleprof {
|
|
|
|
|
2014-11-01 01:56:55 +01:00
|
|
|
enum SampleProfileFormat { SPF_None = 0, SPF_Text, SPF_Binary, SPF_GCC };
|
|
|
|
|
2014-10-30 19:00:06 +01:00
|
|
|
/// \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() {}
|
|
|
|
|
2014-11-01 01:56:55 +01:00
|
|
|
/// \brief Write sample profiles in \p S for function \p FName.
|
2014-10-30 19:00:06 +01:00
|
|
|
///
|
|
|
|
/// \returns true if the file was updated successfully. False, otherwise.
|
2014-11-01 01:56:55 +01:00
|
|
|
virtual bool write(StringRef FName, const FunctionSamples &S) = 0;
|
|
|
|
|
|
|
|
/// \brief Write all the sample profiles in the given map of samples.
|
|
|
|
///
|
|
|
|
/// \returns true if the file was updated successfully. False, otherwise.
|
|
|
|
bool write(StringMap<FunctionSamples> &ProfileMap) {
|
|
|
|
for (auto &I : ProfileMap) {
|
|
|
|
StringRef FName = I.first();
|
|
|
|
FunctionSamples &Profile = I.second;
|
|
|
|
if (!write(FName, Profile))
|
2014-10-30 19:00:06 +01:00
|
|
|
return false;
|
2014-11-01 01:56:55 +01:00
|
|
|
}
|
2014-10-30 19:00:06 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-01 01:56:55 +01:00
|
|
|
/// \brief Profile writer factory. Create a new writer based on the value of
|
|
|
|
/// \p Format.
|
2014-11-03 01:51:45 +01:00
|
|
|
static ErrorOr<std::unique_ptr<SampleProfileWriter>>
|
|
|
|
create(StringRef Filename, SampleProfileFormat Format);
|
2014-11-01 01:56:55 +01:00
|
|
|
|
2014-10-30 19:00:06 +01:00
|
|
|
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)
|
2015-10-08 21:40:37 +02:00
|
|
|
: SampleProfileWriter(F, EC, sys::fs::F_Text), Indent(0) {}
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2014-11-01 01:56:55 +01:00
|
|
|
bool write(StringRef FName, const FunctionSamples &S) override;
|
2015-10-08 21:40:37 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Indent level to use when writing.
|
|
|
|
///
|
|
|
|
/// This is used when printing inlined callees.
|
|
|
|
unsigned Indent;
|
2014-10-30 19:00:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Sample-based profile writer (binary format).
|
|
|
|
class SampleProfileWriterBinary : public SampleProfileWriter {
|
|
|
|
public:
|
|
|
|
SampleProfileWriterBinary(StringRef F, std::error_code &EC);
|
|
|
|
|
2014-11-01 01:56:55 +01:00
|
|
|
bool write(StringRef F, const FunctionSamples &S) override;
|
2014-10-30 19:00:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End namespace sampleprof
|
|
|
|
|
2014-10-30 21:19:19 +01:00
|
|
|
} // End namespace llvm
|
2014-10-30 19:00:06 +01:00
|
|
|
|
|
|
|
#endif // LLVM_PROFILEDATA_SAMPLEPROFWRITER_H
|