Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 1 | //=-- 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" |
| 17 | |
| 18 | using namespace llvm; |
| 19 | |
| 20 | namespace { |
| 21 | class InstrProfErrorCategoryType : public error_category { |
| 22 | const char *name() const override { return "llvm.instrprof"; } |
| 23 | std::string message(int IE) const override { |
Rafael Espindola | 92512e8 | 2014-06-03 05:12:33 +0000 | [diff] [blame] | 24 | instrprof_error E = static_cast<instrprof_error>(IE); |
Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 25 | switch (E) { |
| 26 | case instrprof_error::success: |
| 27 | return "Success"; |
| 28 | case instrprof_error::eof: |
| 29 | return "End of File"; |
| 30 | case instrprof_error::bad_magic: |
| 31 | return "Invalid file format (bad magic)"; |
Duncan P. N. Exon Smith | 531bb48 | 2014-03-21 20:42:28 +0000 | [diff] [blame] | 32 | case instrprof_error::bad_header: |
| 33 | return "Invalid header"; |
Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 34 | case instrprof_error::unsupported_version: |
| 35 | return "Unsupported format version"; |
Justin Bogner | b7aa263 | 2014-04-18 21:48:40 +0000 | [diff] [blame] | 36 | case instrprof_error::unsupported_hash_type: |
| 37 | return "Unsupported hash function"; |
Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 38 | case instrprof_error::too_large: |
| 39 | return "Too much profile data"; |
| 40 | case instrprof_error::truncated: |
| 41 | return "Truncated profile data"; |
| 42 | case instrprof_error::malformed: |
| 43 | return "Malformed profile data"; |
| 44 | case instrprof_error::unknown_function: |
| 45 | return "No profile data available for function"; |
Justin Bogner | b9bd7f8 | 2014-03-21 17:46:22 +0000 | [diff] [blame] | 46 | case instrprof_error::hash_mismatch: |
| 47 | return "Function hash mismatch"; |
| 48 | case instrprof_error::count_mismatch: |
| 49 | return "Function count mismatch"; |
| 50 | case instrprof_error::counter_overflow: |
| 51 | return "Counter overflow"; |
Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 52 | } |
| 53 | llvm_unreachable("A value of instrprof_error has no message."); |
| 54 | } |
Craig Topper | 9d74a5a | 2014-04-29 07:58:41 +0000 | [diff] [blame] | 55 | error_condition default_error_condition(int EV) const override { |
Rafael Espindola | 92512e8 | 2014-06-03 05:12:33 +0000 | [diff] [blame] | 56 | if (static_cast<instrprof_error>(EV) == instrprof_error::success) |
Rafael Espindola | a3f2e3f | 2014-05-31 03:21:04 +0000 | [diff] [blame] | 57 | return error_condition(); |
Justin Bogner | f8d7919 | 2014-03-21 17:24:48 +0000 | [diff] [blame] | 58 | return errc::invalid_argument; |
| 59 | } |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | const error_category &llvm::instrprof_category() { |
| 64 | static InstrProfErrorCategoryType C; |
| 65 | return C; |
| 66 | } |