xref: /llvm-project/bolt/include/bolt/Rewrite/MetadataManager.h (revision 8ea59ec6077e85c457b27b406a679ab9d5827387)
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   /// Run initializers after sections are discovered.
32   void runSectionInitializers();
33 
34   /// Execute initialization of rewriters while functions are disassembled, but
35   /// CFG is not yet built.
36   void runInitializersPreCFG();
37 
38   /// Execute metadata initializers after CFG was constructed for functions.
39   void runInitializersPostCFG();
40 
41   /// Run finalization step of rewriters before the binary is emitted.
42   void runFinalizersPreEmit();
43 
44   /// Run finalization step of rewriters after code has been emitted.
45   void runFinalizersAfterEmit();
46 };
47 
48 } // namespace bolt
49 } // namespace llvm
50 
51 #endif // BOLT_REWRITE_METADATA_MANAGER_H
52