SampleProf.cpp revision 277718
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 19using namespace llvm; 20 21namespace { 22class 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"; 39 case sampleprof_error::unrecognized_format: 40 return "Unrecognized profile encoding format"; 41 } 42 llvm_unreachable("A value of sampleprof_error has no message."); 43 } 44}; 45} 46 47static ManagedStatic<SampleProfErrorCategoryType> ErrorCategory; 48 49const std::error_category &llvm::sampleprof_category() { 50 return *ErrorCategory; 51} 52