LLVM  4.0.0
InstrProfWriter.h
Go to the documentation of this file.
1 //=-- InstrProfWriter.h - Instrumented profiling writer -----------*- C++ -*-=//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains support for writing profiling data for instrumentation
11 // based PGO and coverage.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_PROFILEDATA_INSTRPROFWRITER_H
16 #define LLVM_PROFILEDATA_INSTRPROFWRITER_H
17 
18 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/Support/DataTypes.h"
23 
24 namespace llvm {
25 
26 /// Writer for instrumentation based profile data.
27 class ProfOStream;
28 class InstrProfRecordWriterTrait;
29 
31 public:
34 
35 private:
36  bool Sparse;
37  StringMap<ProfilingData> FunctionData;
38  ProfKind ProfileKind;
39  // Use raw pointer here for the incomplete type object.
41 
42 public:
43  InstrProfWriter(bool Sparse = false);
45 
46  /// Add function counts for the given function. If there are already counts
47  /// for this function and the hash and number of counts match, each counter is
48  /// summed. Optionally scale counts by \p Weight.
49  Error addRecord(InstrProfRecord &&I, uint64_t Weight = 1);
50  /// Merge existing function counts from the given writer.
52  /// Write the profile to \c OS
53  void write(raw_fd_ostream &OS);
54  /// Write the profile in text format to \c OS
55  void writeText(raw_fd_ostream &OS);
56  /// Write \c Record in text format to \c OS
57  static void writeRecordInText(const InstrProfRecord &Record,
58  InstrProfSymtab &Symtab, raw_fd_ostream &OS);
59  /// Write the profile, returning the raw data. For testing.
60  std::unique_ptr<MemoryBuffer> writeBuffer();
61 
62  /// Set the ProfileKind. Report error if mixing FE and IR level profiles.
63  Error setIsIRLevelProfile(bool IsIRLevel) {
64  if (ProfileKind == PF_Unknown) {
65  ProfileKind = IsIRLevel ? PF_IRLevel: PF_FE;
66  return Error::success();
67  }
68  return (IsIRLevel == (ProfileKind == PF_IRLevel))
69  ? Error::success()
70  : make_error<InstrProfError>(
72  }
73 
74  // Internal interface for testing purpose only.
76  void setOutputSparse(bool Sparse);
77 
78 private:
79  bool shouldEncodeData(const ProfilingData &PD);
80  void writeImpl(ProfOStream &OS);
81 };
82 
83 } // end namespace llvm
84 
85 #endif
void setValueProfDataEndianness(support::endianness Endianness)
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
Definition: InstrProf.h:416
Error addRecord(InstrProfRecord &&I, uint64_t Weight=1)
Add function counts for the given function.
InstrProfWriter(bool Sparse=false)
void writeText(raw_fd_ostream &OS)
Write the profile in text format to OS.
void setOutputSparse(bool Sparse)
Error mergeRecordsFromWriter(InstrProfWriter &&IPW)
Merge existing function counts from the given writer.
static ErrorSuccess success()
Create a success value.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:223
Error setIsIRLevelProfile(bool IsIRLevel)
Set the ProfileKind. Report error if mixing FE and IR level profiles.
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:357
Profiling information for a single function.
Definition: InstrProf.h:581
SmallDenseMap< uint64_t, InstrProfRecord, 1 > ProfilingData
#define I(x, y, z)
Definition: MD5.cpp:54
void write(raw_fd_ostream &OS)
Write the profile to OS.
Lightweight error class with error context and mandatory checking.
std::unique_ptr< MemoryBuffer > writeBuffer()
Write the profile, returning the raw data. For testing.
static void writeRecordInText(const InstrProfRecord &Record, InstrProfSymtab &Symtab, raw_fd_ostream &OS)
Write Record in text format to OS.