5c9a5b693dd7a1ff81f4bd9af44c58ea18849e61
[oota-llvm.git] / include / llvm / ProfileData / InstrProf.h
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 <system_error>
21 #include <vector>
22
23 namespace llvm {
24 const std::error_category &instrprof_category();
25
26 enum class instrprof_error {
27     success = 0,
28     eof,
29     bad_magic,
30     bad_header,
31     unsupported_version,
32     unsupported_hash_type,
33     too_large,
34     truncated,
35     malformed,
36     unknown_function,
37     hash_mismatch,
38     count_mismatch,
39     counter_overflow
40 };
41
42 inline std::error_code make_error_code(instrprof_error E) {
43   return std::error_code(static_cast<int>(E), instrprof_category());
44 }
45
46 /// Profiling information for a single function.
47 struct InstrProfRecord {
48   InstrProfRecord() {}
49   InstrProfRecord(StringRef Name, uint64_t Hash, std::vector<uint64_t> &Counts)
50       : Name(Name), Hash(Hash), Counts(std::move(Counts)) {}
51   StringRef Name;
52   uint64_t Hash;
53   std::vector<uint64_t> Counts;
54 };
55
56 } // end namespace llvm
57
58 namespace std {
59 template <>
60 struct is_error_code_enum<llvm::instrprof_error> : std::true_type {};
61 }
62
63 #endif // LLVM_PROFILEDATA_INSTRPROF_H_