-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassSupport.h
90 lines (80 loc) · 3.18 KB
/
PassSupport.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include <Windows.h>
#include <map>
#include <vector>
#include <string>
#include "PassManager.h"
#include "Passes.h"
namespace cchips {
class Pass;
class PassManager;
class PassInfo {
public:
using passinfo_handle = enum {
passreg_pre,
passreg_post,
};
using NormalCtor_t = std::unique_ptr<Pass> (*)();
PassInfo(std::string_view name, std::string_view desc, passinfo_handle handle, const void *pi, NormalCtor_t normal)
: PassName(name), PassDesc(desc), RegHandle(handle), PassID(pi), NormalCtor(normal) {}
std::string_view getPassName() const { return PassName; }
std::string_view getPassDesc() const { return PassDesc; }
AnalysisID getPassID() const { return PassID; }
std::unique_ptr<Pass> getPass() const { return std::move(NormalCtor()); }
bool valid() const {
if (!PassName.length() || !PassID || !NormalCtor)
return false;
if (RegHandle != passreg_pre && RegHandle != passreg_post)
return false;
return true;
}
passinfo_handle getRegHandle() const { return RegHandle; }
private:
std::string_view PassName;
std::string_view PassDesc;
passinfo_handle RegHandle;
AnalysisID PassID;
NormalCtor_t NormalCtor = nullptr;
};
class PassRegistry
{
public:
static PassRegistry& getPassRegistry() {
static PassRegistry m_instance;
return m_instance;
}
void Initialize();
const PassInfo* getPassInfo(AnalysisID ID) const;
const PassInfo* getPassInfo(const std::string& pass_name) const;
std::unique_ptr<Pass> getPass(AnalysisID ID) const;
std::unique_ptr<Pass> getPass(const std::string& pass_name) const;
void registerPass(PassInfo &PI);
std::shared_ptr<PassManagerBase> getPassManager(Pass::passmanager_type type) const;
bool sequence(std::vector<std::string>& sequence_list);
bool run(std::shared_ptr<Module> PM);
bool run(std::shared_ptr<Function> PF);
bool run(std::shared_ptr<BasicBlock> PB);
bool run(std::shared_ptr<CapInsn> PC);
AnalysisID GetPassID(const std::string& pass_name);
static std::vector<std::string> sequence_passes_define;
private:
PassRegistry() {
Initialize();
}
~PassRegistry() = default;
std::vector<PassInfo> passinfos;
std::vector<std::shared_ptr<PassManagerBase>> passmanagerbases;
};
template <typename PassName> std::unique_ptr<Pass> callDefaultCtor() {
return std::make_unique<PassName>();
}
template <typename passName> struct RegisterPass : PassInfo {
// Register Pass using default constructor...
RegisterPass(std::string_view Name, std::string_view PassDesc, PassInfo::passinfo_handle handle)
: PassInfo(Name, PassDesc, handle, &passName::ID,
PassInfo::NormalCtor_t(callDefaultCtor<passName>)) {
PassRegistry::getPassRegistry().registerPass(*this);
}
};
#define GetPassRegistry() PassRegistry::getPassRegistry()
} // namespace cchips