Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 1 | //=-- SampleProf.cpp - Sample 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 common definitions used in the reading and writing of |
| 11 | // sample profile data. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/ProfileData/SampleProf.h" |
| 16 | #include "llvm/Support/ErrorHandling.h" |
| 17 | #include "llvm/Support/ManagedStatic.h" |
| 18 | |
| 19 | using namespace llvm; |
| 20 | |
| 21 | namespace { |
| 22 | class SampleProfErrorCategoryType : public std::error_category { |
| 23 | const char *name() const LLVM_NOEXCEPT override { return "llvm.sampleprof"; } |
| 24 | std::string message(int IE) const override { |
| 25 | sampleprof_error E = static_cast<sampleprof_error>(IE); |
| 26 | switch (E) { |
| 27 | case sampleprof_error::success: |
| 28 | return "Success"; |
| 29 | case sampleprof_error::bad_magic: |
| 30 | return "Invalid file format (bad magic)"; |
| 31 | case sampleprof_error::unsupported_version: |
| 32 | return "Unsupported format version"; |
| 33 | case sampleprof_error::too_large: |
| 34 | return "Too much profile data"; |
| 35 | case sampleprof_error::truncated: |
| 36 | return "Truncated profile data"; |
| 37 | case sampleprof_error::malformed: |
| 38 | return "Malformed profile data"; |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 39 | case sampleprof_error::unrecognized_format: |
| 40 | return "Unrecognized profile encoding format"; |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 41 | } |
| 42 | llvm_unreachable("A value of sampleprof_error has no message."); |
| 43 | } |
| 44 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame^] | 45 | } |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 46 | |
| 47 | static ManagedStatic<SampleProfErrorCategoryType> ErrorCategory; |
| 48 | |
| 49 | const std::error_category &llvm::sampleprof_category() { |
| 50 | return *ErrorCategory; |
| 51 | } |