136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//=-- InstrProf.cpp - Instrumented profiling format support -----------------=// 236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// 336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// The LLVM Compiler Infrastructure 436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// 536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// This file is distributed under the University of Illinois Open Source 636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// License. See LICENSE.TXT for details. 736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// 836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//===----------------------------------------------------------------------===// 936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// 1036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// This file contains support for clang's instrumentation based PGO and 1136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// coverage. 1236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// 1336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//===----------------------------------------------------------------------===// 1436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 1536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/ProfileData/InstrProf.h" 1636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/Support/ErrorHandling.h" 1736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 1836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesusing namespace llvm; 1936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 2036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesnamespace { 21cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesclass InstrProfErrorCategoryType : public std::error_category { 22cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines const char *name() const LLVM_NOEXCEPT override { return "llvm.instrprof"; } 2336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines std::string message(int IE) const override { 24cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines instrprof_error E = static_cast<instrprof_error>(IE); 2536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines switch (E) { 2636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::success: 2736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "Success"; 2836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::eof: 2936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "End of File"; 3036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::bad_magic: 3136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "Invalid file format (bad magic)"; 3236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::bad_header: 3336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "Invalid header"; 3436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::unsupported_version: 3536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "Unsupported format version"; 36dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines case instrprof_error::unsupported_hash_type: 37dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines return "Unsupported hash function"; 3836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::too_large: 3936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "Too much profile data"; 4036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::truncated: 4136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "Truncated profile data"; 4236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::malformed: 4336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "Malformed profile data"; 4436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::unknown_function: 4536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "No profile data available for function"; 4636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::hash_mismatch: 4736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "Function hash mismatch"; 4836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::count_mismatch: 4936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "Function count mismatch"; 5036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines case instrprof_error::counter_overflow: 5136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return "Counter overflow"; 5236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 5336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines llvm_unreachable("A value of instrprof_error has no message."); 5436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 5536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}; 5636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines} 5736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 58cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hinesconst std::error_category &llvm::instrprof_category() { 5936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines static InstrProfErrorCategoryType C; 6036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return C; 6136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines} 62