4#include <unordered_map>
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>
17extern llvm::cl::opt<std::string>
IndexFile;
23inline T&
indirect(
const std::unique_ptr<T>& ptr) {
27class GlobalCFGAnalysis;
44 std::unique_ptr<sdfg::StructuredSDFG> current_;
45 std::shared_mutex current_mutex_;
59 llvm::LLVMContext Ctx_;
61 std::unordered_map<std::string, std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>> registry_;
63 std::unique_ptr<llvm::ModuleSummaryIndex> combined_index_;
65 std::unordered_map<std::string, Attributes> attributes_;
67 std::unordered_map<std::string, Attributes> external_attributes_;
69 void load(
const llvm::Module& Module);
77 return this->registry_.contains(Module.getName().str());
81 std::vector<std::string> modules;
82 for (
const auto& [mod_name, _] : this->registry_) {
83 modules.push_back(mod_name);
91 std::unique_ptr<llvm::Module>
get_module(
const std::string& module_name, llvm::LLVMContext& ctx);
93 std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>&
at(
const std::string& ModuleName) {
94 auto& perMod = this->registry_.at(ModuleName);
99 std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>&
at(
const llvm::StringRef& ModuleName) {
100 return at(ModuleName.str());
104 return this->attributes_.contains(name);
108 return this->external_attributes_.contains(name);
111 std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>&
at(
const llvm::Module& Module) {
112 return at(Module.getName());
116 return this->attributes_.at(name);
120 return this->external_attributes_.at(name);
123 void insert(
const llvm::Module& Module, std::list<std::unique_ptr<sdfg::StructuredSDFG>> sdfgs);
134 std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>& map,
151 std::unordered_map<std::string, std::unique_ptr<SDFGHolder>>& map,
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
T & indirect(const std::unique_ptr< T > &ptr)
Definition sdfg_registry.h:23
llvm::cl::opt< std::string > IndexFile
Definition attributes.h:25