1 //===--- InstrumentationRuntimeLibrary.h - The Instrument Runtime Library -===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_TOOLS_LLVM_BOLT_INSTRUMENTATION_RUNTIME_LIBRARY_H 10 #define LLVM_TOOLS_LLVM_BOLT_INSTRUMENTATION_RUNTIME_LIBRARY_H 11 12 #include "bolt/Passes/InstrumentationSummary.h" 13 #include "bolt/RuntimeLibs/RuntimeLibrary.h" 14 15 namespace llvm { 16 namespace bolt { 17 18 class InstrumentationRuntimeLibrary : public RuntimeLibrary { 19 public: 20 void setSummary(std::unique_ptr<InstrumentationSummary> &&S) { 21 Summary.swap(S); 22 } 23 24 void addRuntimeLibSections(std::vector<std::string> &SecNames) const final { 25 SecNames.push_back(".bolt.instr.counters"); 26 } 27 28 void adjustCommandLineOptions(const BinaryContext &BC) const final; 29 30 void emitBinary(BinaryContext &BC, MCStreamer &Streamer) final; 31 32 void link(BinaryContext &BC, StringRef ToolPath, RuntimeDyld &RTDyld, 33 std::function<void(RuntimeDyld &)> OnLoad) final; 34 35 private: 36 std::string buildTables(BinaryContext &BC); 37 38 /// Create a non-allocatable ELF section with read-only tables necessary for 39 /// writing the instrumented data profile during program finish. The runtime 40 /// library needs to open the program executable file and read this data from 41 /// disk, this is not loaded by the system. 42 void emitTablesAsELFNote(BinaryContext &BC); 43 44 std::unique_ptr<InstrumentationSummary> Summary; 45 }; 46 47 } // namespace bolt 48 } // namespace llvm 49 50 #endif 51