xref: /llvm-project/bolt/include/bolt/Rewrite/BinaryPassManager.h (revision 13d60ce2f262ef9055389908b63824e53b3054a1)
1 //===- bolt/Rewrite/BinaryPassManager.h - Binary-level passes ---*- 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 // A very simple binary-level analysis/optimization passes system.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef BOLT_REWRITE_BINARY_PASS_MANAGER_H
14 #define BOLT_REWRITE_BINARY_PASS_MANAGER_H
15 
16 #include "bolt/Passes/BinaryPasses.h"
17 #include <memory>
18 #include <vector>
19 
20 namespace llvm {
21 namespace bolt {
22 class BinaryContext;
23 
24 /// Simple class for managing analyses and optimizations on BinaryFunctions.
25 class BinaryFunctionPassManager {
26 private:
27   BinaryContext &BC;
28   std::vector<std::pair<const bool, std::unique_ptr<BinaryFunctionPass>>>
29       Passes;
30 
31 public:
32   static const char TimerGroupName[];
33   static const char TimerGroupDesc[];
34 
BinaryFunctionPassManager(BinaryContext & BC)35   BinaryFunctionPassManager(BinaryContext &BC) : BC(BC) {}
36 
37   /// Adds a pass to this manager based on the value of its corresponding
38   /// command-line option.
registerPass(std::unique_ptr<BinaryFunctionPass> Pass,const bool Run)39   void registerPass(std::unique_ptr<BinaryFunctionPass> Pass, const bool Run) {
40     Passes.emplace_back(Run, std::move(Pass));
41   }
42 
43   /// Adds an unconditionally run pass to this manager.
registerPass(std::unique_ptr<BinaryFunctionPass> Pass)44   void registerPass(std::unique_ptr<BinaryFunctionPass> Pass) {
45     Passes.emplace_back(true, std::move(Pass));
46   }
47 
48   /// Run all registered passes in the order they were added.
49   Error runPasses();
50 
51   /// Runs all enabled implemented passes on all functions.
52   static Error runAllPasses(BinaryContext &BC);
53 };
54 
55 } // namespace bolt
56 } // namespace llvm
57 
58 #endif // BOLT_REWRITE_BINARY_PASS_MANAGER_H
59