SampleProf.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "llvm/ProfileData/SampleProf.h"
  15. #include "llvm/Support/ErrorHandling.h"
  16. #include "llvm/Support/ManagedStatic.h"
  17. using namespace llvm;
  18. namespace {
  19. class SampleProfErrorCategoryType : public std::error_category {
  20. const char *name() const LLVM_NOEXCEPT override { return "llvm.sampleprof"; }
  21. std::string message(int IE) const override {
  22. sampleprof_error E = static_cast<sampleprof_error>(IE);
  23. switch (E) {
  24. case sampleprof_error::success:
  25. return "Success";
  26. case sampleprof_error::bad_magic:
  27. return "Invalid file format (bad magic)";
  28. case sampleprof_error::unsupported_version:
  29. return "Unsupported format version";
  30. case sampleprof_error::too_large:
  31. return "Too much profile data";
  32. case sampleprof_error::truncated:
  33. return "Truncated profile data";
  34. case sampleprof_error::malformed:
  35. return "Malformed profile data";
  36. case sampleprof_error::unrecognized_format:
  37. return "Unrecognized profile encoding format";
  38. }
  39. llvm_unreachable("A value of sampleprof_error has no message.");
  40. }
  41. };
  42. }
  43. static ManagedStatic<SampleProfErrorCategoryType> ErrorCategory;
  44. const std::error_category &llvm::sampleprof_category() {
  45. return *ErrorCategory;
  46. }