1 //=-- InstrProf.h - Instrumented profiling format support ---------*- 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 // Instrumentation-based profiling data is generated by instrumented
11 // binaries through library functions in compiler-rt, and read by the clang
12 // frontend to feed PGO.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_PROFILEDATA_INSTRPROF_H_
17 #define LLVM_PROFILEDATA_INSTRPROF_H_
18
19 #include "llvm/ADT/StringRef.h"
20 #include <cstdint>
21 #include <system_error>
22 #include <vector>
23
24 namespace llvm {
25 const std::error_category &instrprof_category();
26
27 enum class instrprof_error {
28 success = 0,
29 eof,
30 bad_magic,
31 bad_header,
32 unsupported_version,
33 unsupported_hash_type,
34 too_large,
35 truncated,
36 malformed,
37 unknown_function,
38 hash_mismatch,
39 count_mismatch,
40 counter_overflow
41 };
42
make_error_code(instrprof_error E)43 inline std::error_code make_error_code(instrprof_error E) {
44 return std::error_code(static_cast<int>(E), instrprof_category());
45 }
46
47 /// Profiling information for a single function.
48 struct InstrProfRecord {
InstrProfRecordInstrProfRecord49 InstrProfRecord() {}
InstrProfRecordInstrProfRecord50 InstrProfRecord(StringRef Name, uint64_t Hash, std::vector<uint64_t> Counts)
51 : Name(Name), Hash(Hash), Counts(std::move(Counts)) {}
52 StringRef Name;
53 uint64_t Hash;
54 std::vector<uint64_t> Counts;
55 };
56
57 } // end namespace llvm
58
59 namespace std {
60 template <>
61 struct is_error_code_enum<llvm::instrprof_error> : std::true_type {};
62 }
63
64 #endif // LLVM_PROFILEDATA_INSTRPROF_H_
65