xref: /llvm-project/bolt/include/bolt/RuntimeLibs/InstrumentationRuntimeLibrary.h (revision 05634f7346a59f6dab89cde53f39b40d9a70b9c9)
1 //===- bolt/RuntimeLibs/InstrumentationRuntimeLibrary.h ---------*- C++ -*-===//
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 // This file contains the declaration of the InstrumentationRuntimeLibrary
10 // class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef BOLT_RUNTIMELIBS_INSTRUMENTATION_RUNTIME_LIBRARY_H
15 #define BOLT_RUNTIMELIBS_INSTRUMENTATION_RUNTIME_LIBRARY_H
16 
17 #include "bolt/Passes/InstrumentationSummary.h"
18 #include "bolt/RuntimeLibs/RuntimeLibrary.h"
19 #include <memory>
20 
21 namespace llvm {
22 namespace bolt {
23 
24 class InstrumentationRuntimeLibrary : public RuntimeLibrary {
25 public:
setSummary(std::unique_ptr<InstrumentationSummary> && S)26   void setSummary(std::unique_ptr<InstrumentationSummary> &&S) {
27     Summary.swap(S);
28   }
29 
addRuntimeLibSections(std::vector<std::string> & SecNames)30   void addRuntimeLibSections(std::vector<std::string> &SecNames) const final {
31     SecNames.push_back(".bolt.instr.counters");
32   }
33 
34   void adjustCommandLineOptions(const BinaryContext &BC) const final;
35 
36   void emitBinary(BinaryContext &BC, MCStreamer &Streamer) final;
37 
38   void link(BinaryContext &BC, StringRef ToolPath, BOLTLinker &Linker,
39             BOLTLinker::SectionsMapper MapSections) override;
40 
41 private:
42   std::string buildTables(BinaryContext &BC);
43 
44   /// Create a non-allocatable ELF section with read-only tables necessary for
45   /// writing the instrumented data profile during program finish. The runtime
46   /// library needs to open the program executable file and read this data from
47   /// disk, this is not loaded by the system.
48   void emitTablesAsELFNote(BinaryContext &BC);
49 
50   std::unique_ptr<InstrumentationSummary> Summary;
51 };
52 
53 } // namespace bolt
54 } // namespace llvm
55 
56 #endif
57