2014-03-21 17:46:22 +00:00
|
|
|
//=-- InstrProfWriter.h - Instrumented profiling writer -----------*- C++ -*-=//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains support for writing profiling data for instrumentation
|
|
|
|
// based PGO and coverage.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_PROFILEDATA_INSTRPROFWRITER_H
|
|
|
|
#define LLVM_PROFILEDATA_INSTRPROFWRITER_H
|
2014-03-21 17:46:22 +00:00
|
|
|
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2014-08-01 22:50:07 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2014-03-21 17:46:22 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ProfileData/InstrProf.h"
|
|
|
|
#include "llvm/Support/DataTypes.h"
|
2015-02-18 01:58:17 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2014-03-21 17:46:22 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
/// Writer for instrumentation based profile data.
|
|
|
|
class InstrProfWriter {
|
|
|
|
public:
|
2014-08-01 22:50:07 +00:00
|
|
|
typedef SmallDenseMap<uint64_t, std::vector<uint64_t>, 1> CounterData;
|
2014-03-21 17:46:22 +00:00
|
|
|
private:
|
|
|
|
StringMap<CounterData> FunctionData;
|
2014-08-01 22:50:07 +00:00
|
|
|
uint64_t MaxFunctionCount;
|
2014-03-21 17:46:22 +00:00
|
|
|
public:
|
2014-08-01 22:50:07 +00:00
|
|
|
InstrProfWriter() : MaxFunctionCount(0) {}
|
|
|
|
|
2014-03-21 17:46:22 +00:00
|
|
|
/// Add function counts for the given function. If there are already counts
|
|
|
|
/// for this function and the hash and number of counts match, each counter is
|
|
|
|
/// summed.
|
2014-06-12 21:46:39 +00:00
|
|
|
std::error_code addFunctionCounts(StringRef FunctionName,
|
|
|
|
uint64_t FunctionHash,
|
|
|
|
ArrayRef<uint64_t> Counters);
|
2015-02-18 01:58:17 +00:00
|
|
|
/// Write the profile to \c OS
|
2014-04-18 21:48:40 +00:00
|
|
|
void write(raw_fd_ostream &OS);
|
2015-02-18 01:58:17 +00:00
|
|
|
/// Write the profile, returning the raw data. For testing.
|
|
|
|
std::unique_ptr<MemoryBuffer> writeBuffer();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::pair<uint64_t, uint64_t> writeImpl(raw_ostream &OS);
|
2014-03-21 17:46:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#endif
|