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
20namespace llvm {
21namespace bolt {
22class BinaryContext;
23
24/// Simple class for managing analyses and optimizations on BinaryFunctions.
25class BinaryFunctionPassManager {
26private:
27 BinaryContext &BC;
28 std::vector<std::pair<const bool, std::unique_ptr<BinaryFunctionPass>>>
29 Passes;
30
31public:
32 static const char TimerGroupName[];
33 static const char TimerGroupDesc[];
34
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.
39 void registerPass(std::unique_ptr<BinaryFunctionPass> Pass, const bool Run) {
40 Passes.emplace_back(args: Run, args: std::move(Pass));
41 }
42
43 /// Adds an unconditionally run pass to this manager.
44 void registerPass(std::unique_ptr<BinaryFunctionPass> Pass) {
45 Passes.emplace_back(args: true, args: 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

source code of bolt/include/bolt/Rewrite/BinaryPassManager.h