1 //=-- InstrProfWriter.h - Instrumented profiling writer -----------*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing profiling data for instrumentation
11 // based PGO and coverage.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_PROFILEDATA_INSTRPROFWRITER_H
16 #define LLVM_PROFILEDATA_INSTRPROFWRITER_H
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ProfileData/InstrProf.h"
20 #include "llvm/Support/DataTypes.h"
21 #include "llvm/Support/MemoryBuffer.h"
22 #include "llvm/Support/raw_ostream.h"
26 /// Writer for instrumentation based profile data.
27 class InstrProfWriter {
29 typedef SmallDenseMap<uint64_t, InstrProfRecord, 1> ProfilingData;
32 StringMap<ProfilingData> FunctionData;
33 uint64_t MaxFunctionCount;
36 InstrProfWriter() : MaxFunctionCount(0) {}
38 /// Add function counts for the given function. If there are already counts
39 /// for this function and the hash and number of counts match, each counter is
40 /// summed. Optionally scale counts by \p Weight.
41 std::error_code addRecord(InstrProfRecord &&I, uint64_t Weight = 1);
42 /// Write the profile to \c OS
43 void write(raw_fd_ostream &OS);
44 /// Write the profile in text format to \c OS
45 void writeText(raw_fd_ostream &OS);
46 /// Write \c Record in text format to \c OS
47 static void writeRecordInText(const InstrProfRecord &Record,
48 InstrProfSymtab &Symtab, raw_fd_ostream &OS);
49 /// Write the profile, returning the raw data. For testing.
50 std::unique_ptr<MemoryBuffer> writeBuffer();
52 // Internal interface for testing purpose only.
53 void setValueProfDataEndianness(support::endianness Endianness);
56 std::pair<uint64_t, uint64_t> writeImpl(raw_ostream &OS);
59 } // end namespace llvm