blob: 805d6d16aace639fd1245a5727347a348d66c6d3 [file] [log] [blame]
Justin Bognerf8d79192014-03-21 17:24:48 +00001//=-- InstrProf.cpp - Instrumented profiling format support -----------------=//
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 clang's instrumentation based PGO and
11// coverage.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/ProfileData/InstrProf.h"
16#include "llvm/Support/ErrorHandling.h"
Chris Bieneman1efe8012014-09-19 23:19:24 +000017#include "llvm/Support/ManagedStatic.h"
Justin Bognerf8d79192014-03-21 17:24:48 +000018
19using namespace llvm;
20
21namespace {
Rafael Espindola25188c92014-06-12 01:45:43 +000022class InstrProfErrorCategoryType : public std::error_category {
Rafael Espindolaf5d07fa2014-06-10 21:26:47 +000023 const char *name() const LLVM_NOEXCEPT override { return "llvm.instrprof"; }
Justin Bognerf8d79192014-03-21 17:24:48 +000024 std::string message(int IE) const override {
Rafael Espindola92512e82014-06-03 05:12:33 +000025 instrprof_error E = static_cast<instrprof_error>(IE);
Justin Bognerf8d79192014-03-21 17:24:48 +000026 switch (E) {
27 case instrprof_error::success:
28 return "Success";
29 case instrprof_error::eof:
30 return "End of File";
31 case instrprof_error::bad_magic:
Justin Bogner367a9f22015-05-06 23:19:35 +000032 return "Invalid profile data (bad magic)";
Duncan P. N. Exon Smith531bb482014-03-21 20:42:28 +000033 case instrprof_error::bad_header:
Justin Bogner367a9f22015-05-06 23:19:35 +000034 return "Invalid profile data (file header is corrupt)";
Justin Bognerf8d79192014-03-21 17:24:48 +000035 case instrprof_error::unsupported_version:
Justin Bogner367a9f22015-05-06 23:19:35 +000036 return "Unsupported profiling format version";
Justin Bognerb7aa2632014-04-18 21:48:40 +000037 case instrprof_error::unsupported_hash_type:
Justin Bogner367a9f22015-05-06 23:19:35 +000038 return "Unsupported profiling hash";
Justin Bognerf8d79192014-03-21 17:24:48 +000039 case instrprof_error::too_large:
40 return "Too much profile data";
41 case instrprof_error::truncated:
42 return "Truncated profile data";
43 case instrprof_error::malformed:
44 return "Malformed profile data";
45 case instrprof_error::unknown_function:
46 return "No profile data available for function";
Justin Bognerb9bd7f82014-03-21 17:46:22 +000047 case instrprof_error::hash_mismatch:
48 return "Function hash mismatch";
49 case instrprof_error::count_mismatch:
50 return "Function count mismatch";
51 case instrprof_error::counter_overflow:
52 return "Counter overflow";
Justin Bognerf8d79192014-03-21 17:24:48 +000053 }
54 llvm_unreachable("A value of instrprof_error has no message.");
55 }
Justin Bognerf8d79192014-03-21 17:24:48 +000056};
Alexander Kornienko70bc5f12015-06-19 15:57:42 +000057} // namespace
Justin Bognerf8d79192014-03-21 17:24:48 +000058
Chris Bieneman1efe8012014-09-19 23:19:24 +000059static ManagedStatic<InstrProfErrorCategoryType> ErrorCategory;
60
Rafael Espindola25188c92014-06-12 01:45:43 +000061const std::error_category &llvm::instrprof_category() {
Chris Bieneman1efe8012014-09-19 23:19:24 +000062 return *ErrorCategory;
Justin Bognerf8d79192014-03-21 17:24:48 +000063}