diff options
| author | Justin Bogner <mail@justinbogner.com> | 2014-03-21 17:24:48 +0000 |
|---|---|---|
| committer | Justin Bogner <mail@justinbogner.com> | 2014-03-21 17:24:48 +0000 |
| commit | f8d791983cfc4a86a6d1a7186aa65bfbecf4c5c5 (patch) | |
| tree | 6c24d9230524c8d8f984e849127965661a814767 /llvm/lib | |
| parent | d8eb29ecfd7ec7f4744bc7ea52e13bbebecea430 (diff) | |
| download | bcm5719-llvm-f8d791983cfc4a86a6d1a7186aa65bfbecf4c5c5.tar.gz bcm5719-llvm-f8d791983cfc4a86a6d1a7186aa65bfbecf4c5c5.zip | |
ProfileData: Introduce the InstrProfReader interface and a text reader
This introduces the ProfileData library and updates llvm-profdata to
use this library for reading profiles. InstrProfReader is an abstract
base class that will be subclassed for both the raw instrprof data
from compiler-rt and the efficient instrprof format that will be used
for PGO.
llvm-svn: 204482
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | llvm/lib/LLVMBuild.txt | 2 | ||||
| -rw-r--r-- | llvm/lib/Makefile | 2 | ||||
| -rw-r--r-- | llvm/lib/ProfileData/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 56 | ||||
| -rw-r--r-- | llvm/lib/ProfileData/InstrProfReader.cpp | 84 | ||||
| -rw-r--r-- | llvm/lib/ProfileData/LLVMBuild.txt | 22 | ||||
| -rw-r--r-- | llvm/lib/ProfileData/Makefile | 14 |
8 files changed, 186 insertions, 2 deletions
diff --git a/llvm/lib/CMakeLists.txt b/llvm/lib/CMakeLists.txt index 9367f553134..fab1c8747b9 100644 --- a/llvm/lib/CMakeLists.txt +++ b/llvm/lib/CMakeLists.txt @@ -16,3 +16,4 @@ add_subdirectory(ExecutionEngine) add_subdirectory(Target) add_subdirectory(AsmParser) add_subdirectory(LineEditor) +add_subdirectory(ProfileData) diff --git a/llvm/lib/LLVMBuild.txt b/llvm/lib/LLVMBuild.txt index a0984d410c6..ad5b22b914e 100644 --- a/llvm/lib/LLVMBuild.txt +++ b/llvm/lib/LLVMBuild.txt @@ -16,7 +16,7 @@ ;===------------------------------------------------------------------------===; [common] -subdirectories = Analysis AsmParser Bitcode CodeGen DebugInfo ExecutionEngine LineEditor Linker IR IRReader LTO MC Object Option Support TableGen Target Transforms +subdirectories = Analysis AsmParser Bitcode CodeGen DebugInfo ExecutionEngine LineEditor Linker IR IRReader LTO MC Object Option ProfileData Support TableGen Target Transforms [component_0] type = Group diff --git a/llvm/lib/Makefile b/llvm/lib/Makefile index a97f71aded0..0ddf917599f 100644 --- a/llvm/lib/Makefile +++ b/llvm/lib/Makefile @@ -12,6 +12,6 @@ include $(LEVEL)/Makefile.config PARALLEL_DIRS := IR AsmParser Bitcode Analysis Transforms CodeGen Target \ ExecutionEngine Linker LTO MC Object Option DebugInfo \ - IRReader LineEditor + IRReader LineEditor ProfileData include $(LEVEL)/Makefile.common diff --git a/llvm/lib/ProfileData/CMakeLists.txt b/llvm/lib/ProfileData/CMakeLists.txt new file mode 100644 index 00000000000..cef3a5336bd --- /dev/null +++ b/llvm/lib/ProfileData/CMakeLists.txt @@ -0,0 +1,7 @@ +add_llvm_library(LLVMProfileData + InstrProf.cpp + InstrProfReader.cpp + + LINK_LIBS + LLVMSupport +) diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp new file mode 100644 index 00000000000..329abf84e6e --- /dev/null +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -0,0 +1,56 @@ +//=-- InstrProf.cpp - Instrumented profiling format support -----------------=// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains support for clang's instrumentation based PGO and +// coverage. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ProfileData/InstrProf.h" +#include "llvm/Support/ErrorHandling.h" + +using namespace llvm; + +namespace { +class InstrProfErrorCategoryType : public error_category { + const char *name() const override { return "llvm.instrprof"; } + std::string message(int IE) const override { + instrprof_error::ErrorType E = static_cast<instrprof_error::ErrorType>(IE); + switch (E) { + case instrprof_error::success: + return "Success"; + case instrprof_error::eof: + return "End of File"; + case instrprof_error::bad_magic: + return "Invalid file format (bad magic)"; + case instrprof_error::unsupported_version: + return "Unsupported format version"; + case instrprof_error::too_large: + return "Too much profile data"; + case instrprof_error::truncated: + return "Truncated profile data"; + case instrprof_error::malformed: + return "Malformed profile data"; + case instrprof_error::unknown_function: + return "No profile data available for function"; + } + llvm_unreachable("A value of instrprof_error has no message."); + } + error_condition default_error_condition(int EV) const { + if (EV == instrprof_error::success) + return errc::success; + return errc::invalid_argument; + } +}; +} + +const error_category &llvm::instrprof_category() { + static InstrProfErrorCategoryType C; + return C; +} diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp new file mode 100644 index 00000000000..8b3600090b8 --- /dev/null +++ b/llvm/lib/ProfileData/InstrProfReader.cpp @@ -0,0 +1,84 @@ +//=-- InstrProfReader.cpp - Instrumented profiling reader -------------------=// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains support for reading profiling data for clang's +// instrumentation based PGO and coverage. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ProfileData/InstrProfReader.h" +#include "llvm/ProfileData/InstrProf.h" +#include "llvm/Support/Endian.h" + +#include <cassert> + +using namespace llvm; + +error_code InstrProfReader::create(std::string Path, + std::unique_ptr<InstrProfReader> &Result) { + std::unique_ptr<MemoryBuffer> Buffer; + if (error_code EC = MemoryBuffer::getFileOrSTDIN(Path, Buffer)) + return EC; + + // Sanity check the file. + if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max()) + return instrprof_error::too_large; + + // FIXME: This needs to determine which format the file is and construct the + // correct subclass. + Result.reset(new TextInstrProfReader(Buffer)); + + return instrprof_error::success; +} + +void InstrProfIterator::Increment() { + if (Reader->readNextRecord(Record)) + *this = InstrProfIterator(); +} + +error_code TextInstrProfReader::readNextRecord(InstrProfRecord &Record) { + // Skip empty lines. + while (!Line.is_at_end() && Line->empty()) + ++Line; + // If we hit EOF while looking for a name, we're done. + if (Line.is_at_end()) + return error(instrprof_error::eof); + + // Read the function name. + Record.Name = *Line++; + + // Read the function hash. + if (Line.is_at_end()) + return error(instrprof_error::truncated); + if ((Line++)->getAsInteger(10, Record.Hash)) + return error(instrprof_error::malformed); + + // Read the number of counters. + uint64_t NumCounters; + if (Line.is_at_end()) + return error(instrprof_error::truncated); + if ((Line++)->getAsInteger(10, NumCounters)) + return error(instrprof_error::malformed); + + // Read each counter and fill our internal storage with the values. + Counts.clear(); + Counts.reserve(NumCounters); + for (uint64_t I = 0; I < NumCounters; ++I) { + if (Line.is_at_end()) + return error(instrprof_error::truncated); + uint64_t Count; + if ((Line++)->getAsInteger(10, Count)) + return error(instrprof_error::malformed); + Counts.push_back(Count); + } + // Give the record a reference to our internal counter storage. + Record.Counts = Counts; + + return success(); +} diff --git a/llvm/lib/ProfileData/LLVMBuild.txt b/llvm/lib/ProfileData/LLVMBuild.txt new file mode 100644 index 00000000000..0a8cbe33632 --- /dev/null +++ b/llvm/lib/ProfileData/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./lib/ProfileData/LLVMBuild.txt --------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = ProfileData +parent = Libraries +required_libraries = Support diff --git a/llvm/lib/ProfileData/Makefile b/llvm/lib/ProfileData/Makefile new file mode 100644 index 00000000000..26743612d3d --- /dev/null +++ b/llvm/lib/ProfileData/Makefile @@ -0,0 +1,14 @@ +##===- lib/ProfileData/Makefile ----------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../.. +LIBRARYNAME = LLVMProfileData +BUILD_ARCHIVE := 1 + +include $(LEVEL)/Makefile.common |

