-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
BinaryPass.h
71 lines (60 loc) · 2.08 KB
/
BinaryPass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//===--- BinaryPass.h - Binary-level analysis/optimization passes ---------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// A very simple binary-level analysis/optimization passes system.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TOOLS_LLVM_BOLT_BINARY_FUNCTION_PASS_H
#define LLVM_TOOLS_LLVM_BOLT_BINARY_FUNCTION_PASS_H
#include "BinaryFunction.h"
#include "llvm/Support/Options.h"
#include "llvm/Support/CommandLine.h"
#include <map>
#include <memory>
#include <vector>
namespace llvm {
namespace bolt {
/// An optimization/analysis pass that runs on functions.
class BinaryFunctionPass {
public:
virtual ~BinaryFunctionPass() = default;
virtual void runOnFunctions(BinaryContext &BC,
std::map<uint64_t, BinaryFunction> &BFs) = 0;
};
/// Simple class for managing analyses and optimizations on BinaryFunctions.
class BinaryFunctionPassManager {
protected:
BinaryContext &BC;
std::map<uint64_t, BinaryFunction> &BFs;
std::vector<std::unique_ptr<BinaryFunctionPass>> Passes;
public:
BinaryFunctionPassManager(BinaryContext &BC,
std::map<uint64_t, BinaryFunction> &BFs)
: BC(BC), BFs(BFs) {}
/// Adds a pass to this manager based on the value of its corresponding
/// command-line option.
void registerPass(std::unique_ptr<BinaryFunctionPass> Pass,
const cl::opt<bool> &Opt) {
if (Opt) {
Passes.emplace_back(std::move(Pass));
}
}
/// Run all registered passes in the order they were added.
void runPasses() {
for (const auto &Pass : Passes) {
Pass->runOnFunctions(BC, BFs);
}
}
/// Runs all enabled implemented passes on all functions.
static void runAllPasses(BinaryContext &BC,
std::map<uint64_t, BinaryFunction> &Functions);
};
} // namespace bolt
} // namespace llvm
#endif