1 | //===- bolt/Rewrite/MetadataManager.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 | #ifndef BOLT_REWRITE_METADATA_MANAGER_H |
10 | #define BOLT_REWRITE_METADATA_MANAGER_H |
11 | |
12 | #include "bolt/Rewrite/MetadataRewriter.h" |
13 | #include "llvm/ADT/SmallVector.h" |
14 | |
15 | namespace llvm { |
16 | namespace bolt { |
17 | |
18 | class BinaryContext; |
19 | |
20 | /// This class manages a collection of metadata handlers/rewriters. |
21 | /// It is responsible for registering new rewriters and invoking them at |
22 | /// certain stages of the binary processing pipeline. |
23 | class MetadataManager { |
24 | using RewritersListType = SmallVector<std::unique_ptr<MetadataRewriter>, 1>; |
25 | RewritersListType Rewriters; |
26 | |
27 | public: |
28 | /// Register a new \p Rewriter. |
29 | void registerRewriter(std::unique_ptr<MetadataRewriter> Rewriter); |
30 | |
31 | /// Execute initialization of rewriters while functions are disassembled, but |
32 | /// CFG is not yet built. |
33 | void runInitializersPreCFG(); |
34 | |
35 | /// Execute metadata initializers after CFG was constructed for functions. |
36 | void runInitializersPostCFG(); |
37 | |
38 | /// Run finalization step of rewriters before the binary is emitted. |
39 | void runFinalizersPreEmit(); |
40 | |
41 | /// Run finalization step of rewriters after code has been emitted. |
42 | void runFinalizersAfterEmit(); |
43 | }; |
44 | |
45 | } // namespace bolt |
46 | } // namespace llvm |
47 | |
48 | #endif // BOLT_REWRITE_METADATA_MANAGER_H |
49 | |