docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
sdfg_registry.h
Go to the documentation of this file.
1#pragma once
2
3#include <shared_mutex>
4#include <unordered_map>
5
6#include <llvm/ADT/StringRef.h>
7#include <llvm/IR/Module.h>
8#include <llvm/IR/ModuleSummaryIndex.h>
9#include <llvm/Support/CommandLine.h>
10#include <llvm/Support/raw_ostream.h>
11
13
16
17extern llvm::cl::opt<std::string> IndexFile;
18
19namespace docc {
20namespace analysis {
21
22template<typename T>
23inline T& indirect(const std::unique_ptr<T>& ptr) {
24 return *ptr;
25};
26
27class GlobalCFGAnalysis;
28
29class SDFGRegistry;
30
41 friend class SDFGRegistry;
42
43private:
44 std::unique_ptr<sdfg::StructuredSDFG> current_;
45 std::shared_mutex current_mutex_;
46
47public:
48 explicit SDFGHolder(std::unique_ptr<sdfg::StructuredSDFG>& sdfg);
49
50 std::tuple<std::unique_lock<std::shared_mutex>, sdfg::StructuredSDFG*> get_for_modify();
51
52 std::tuple<std::shared_lock<std::shared_mutex>, const sdfg::StructuredSDFG*> get_for_read();
53};
54
55class SDFGRegistry : public Analysis {
56 friend class GlobalCFGAnalysis;
57
58private:
59 llvm::LLVMContext Ctx_;
60
61 std::unordered_map<std::string, std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>> registry_;
62
63 std::unique_ptr<llvm::ModuleSummaryIndex> combined_index_;
64
65 std::unordered_map<std::string, Attributes> attributes_;
66
67 std::unordered_map<std::string, Attributes> external_attributes_;
68
69 void load(const llvm::Module& Module);
70
71public:
72 SDFGRegistry() = default;
73 SDFGRegistry(const SDFGRegistry&) = delete;
75
76 bool has_module(const llvm::Module& Module) const {
77 return this->registry_.contains(Module.getName().str());
78 }
79
80 std::vector<std::string> get_known_modules() {
81 std::vector<std::string> modules;
82 for (const auto& [mod_name, _] : this->registry_) {
83 modules.push_back(mod_name);
84 }
85 return modules;
86 }
87
91 std::unique_ptr<llvm::Module> get_module(const std::string& module_name, llvm::LLVMContext& ctx);
92
93 std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>& at(const std::string& ModuleName) {
94 auto& perMod = this->registry_.at(ModuleName);
95
96 return perMod;
97 }
98
99 std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>& at(const llvm::StringRef& ModuleName) {
100 return at(ModuleName.str());
101 }
102
103 bool has_function(const std::string& name) const {
104 return this->attributes_.contains(name);
105 }
106
107 bool has_external_function(const std::string& name) const {
108 return this->external_attributes_.contains(name);
109 }
110
111 std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>& at(const llvm::Module& Module) {
112 return at(Module.getName());
113 }
114
115 const Attributes& attributes(const std::string& name) const {
116 return this->attributes_.at(name);
117 }
118
119 const Attributes& external_attributes(const std::string& name) const {
120 return this->external_attributes_.at(name);
121 }
122
123 void insert(const llvm::Module& Module, std::list<std::unique_ptr<sdfg::StructuredSDFG>> sdfgs);
124
125 void dump_sdfgs(const llvm::Module& Module);
126
127 void run(AnalysisManager& WPAM);
128
129 static bool is_link_time(AnalysisManager& WPAM);
130
131 static std::filesystem::path docc_extract_dir(const llvm::Module& Module);
132
134 std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>& map,
135 const std::function<void(SDFGHolder&, sdfg::StructuredSDFG&)>& action
136 );
137
139 const llvm::Module& Module, const std::function<void(SDFGHolder&, sdfg::StructuredSDFG&)>& action
140 ) {
141 for_each_sdfg_modifiable(at(Module), action);
142 }
143
144 void for_each_sdfg_modifiable(const llvm::Module& Module, const std::function<void(sdfg::StructuredSDFG&)>& action) {
145 for_each_sdfg_modifiable(at(Module), [&action](SDFGHolder& holder, sdfg::StructuredSDFG& sdfg) {
146 action(sdfg);
147 });
148 }
149
151 std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>& map,
152 const std::function<void(SDFGHolder&, const sdfg::StructuredSDFG&)>& action
153 );
154
156 const llvm::Module& Module, const std::function<void(SDFGHolder&, const sdfg::StructuredSDFG&)>& action
157 ) {
158 for_each_sdfg_modifiable(at(Module), action);
159 }
160
161 void for_each_sdfg_const(const llvm::Module& Module, const std::function<void(const sdfg::StructuredSDFG&)>& action) {
162 for_each_sdfg_const(at(Module), [&action](SDFGHolder& holder, const sdfg::StructuredSDFG& sdfg) {
163 action(sdfg);
164 });
165 }
166};
167
168} // namespace analysis
169} // namespace docc
Definition analysis.h:14
friend class AnalysisManager
Definition analysis.h:15
This a wrapper around 1 SDFG (may include historic versions of the same SDFG in the future).
Definition sdfg_registry.h:40
SDFGHolder(std::unique_ptr< sdfg::StructuredSDFG > &sdfg)
std::tuple< std::unique_lock< std::shared_mutex >, sdfg::StructuredSDFG * > get_for_modify()
std::tuple< std::shared_lock< std::shared_mutex >, const sdfg::StructuredSDFG * > get_for_read()
friend class SDFGRegistry
Definition sdfg_registry.h:41
bool has_external_function(const std::string &name) const
Definition sdfg_registry.h:107
static void for_each_sdfg_const(std::unordered_map< std::string, std::unique_ptr< SDFGHolder > > &map, const std::function< void(SDFGHolder &, const sdfg::StructuredSDFG &)> &action)
void for_each_sdfg_const(const llvm::Module &Module, const std::function< void(SDFGHolder &, const sdfg::StructuredSDFG &)> &action)
Definition sdfg_registry.h:155
std::unique_ptr< llvm::Module > get_module(const std::string &module_name, llvm::LLVMContext &ctx)
Read the module from its file.
static void for_each_sdfg_modifiable(std::unordered_map< std::string, std::unique_ptr< SDFGHolder > > &map, const std::function< void(SDFGHolder &, sdfg::StructuredSDFG &)> &action)
void for_each_sdfg_modifiable(const llvm::Module &Module, const std::function< void(SDFGHolder &, sdfg::StructuredSDFG &)> &action)
Definition sdfg_registry.h:138
static bool is_link_time(AnalysisManager &WPAM)
bool has_function(const std::string &name) const
Definition sdfg_registry.h:103
SDFGRegistry(const SDFGRegistry &)=delete
const Attributes & external_attributes(const std::string &name) const
Definition sdfg_registry.h:119
bool has_module(const llvm::Module &Module) const
Definition sdfg_registry.h:76
std::vector< std::string > get_known_modules()
Definition sdfg_registry.h:80
void insert(const llvm::Module &Module, std::list< std::unique_ptr< sdfg::StructuredSDFG > > sdfgs)
void for_each_sdfg_const(const llvm::Module &Module, const std::function< void(const sdfg::StructuredSDFG &)> &action)
Definition sdfg_registry.h:161
std::unordered_map< std::string, std::unique_ptr< SDFGHolder > > & at(const llvm::StringRef &ModuleName)
Definition sdfg_registry.h:99
const Attributes & attributes(const std::string &name) const
Definition sdfg_registry.h:115
static std::filesystem::path docc_extract_dir(const llvm::Module &Module)
void dump_sdfgs(const llvm::Module &Module)
std::unordered_map< std::string, std::unique_ptr< SDFGHolder > > & at(const llvm::Module &Module)
Definition sdfg_registry.h:111
void run(AnalysisManager &WPAM)
SDFGRegistry & operator=(const SDFGRegistry &)=delete
void for_each_sdfg_modifiable(const llvm::Module &Module, const std::function< void(sdfg::StructuredSDFG &)> &action)
Definition sdfg_registry.h:144
friend class GlobalCFGAnalysis
Definition sdfg_registry.h:56
std::unordered_map< std::string, std::unique_ptr< SDFGHolder > > & at(const std::string &ModuleName)
Definition sdfg_registry.h:93
Definition structured_sdfg.h:30
Definition analysis.h:9
T & indirect(const std::unique_ptr< T > &ptr)
Definition sdfg_registry.h:23
Definition targets.h:8
Definition analysis.h:7
llvm::cl::opt< std::string > IndexFile
Definition attributes.h:25