Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
LambdaRegistry.hpp
Go to the documentation of this file.
1#ifndef PROTEUS_LAMBDA_INTERFACE_HPP
2#define PROTEUS_LAMBDA_INTERFACE_HPP
3
4#include <llvm/ADT/DenseMap.h>
5#include <llvm/ADT/StringRef.h>
6#include <llvm/Demangle/Demangle.h>
7
9#include "proteus/Config.hpp"
10#include "proteus/Debug.h"
11#include "proteus/Error.h"
12#include "proteus/Logger.hpp"
13
14namespace proteus {
15
16using namespace llvm;
17
18// The LambdaRegistry stores the unique lambda type symbol and the values of Jit
19// member variables in a map for retrieval by the Jit engines.
21public:
24 return Singleton;
25 }
26
27 std::optional<DenseMap<StringRef, SmallVector<RuntimeConstant>>::iterator>
29 std::string Operator = llvm::demangle(FnName.str());
30 std::size_t Sep = Operator.rfind("::operator()");
31 if (Sep == std::string::npos) {
32 PROTEUS_DBG(Logger::logs("proteus")
33 << "... SKIP ::operator() not found\n");
34 return std::nullopt;
35 }
36
38 if (Config::get().ProteusDebugOutput) {
39 Logger::logs("proteus")
40 << "Operator " << Operator << "\n=> LambdaType to match "
41 << LambdaType << "\n";
42 Logger::logs("proteus") << "Available Keys\n";
43 for (auto &[Key, Val] : JitVariableMap) {
44 Logger::logs("proteus") << "\tKey: " << Key << "\n";
45 }
46 Logger::logs("proteus") << "===\n";
47 }
48
49 const auto It = JitVariableMap.find(LambdaType);
50 if (It == JitVariableMap.end())
51 return std::nullopt;
52
53 return It;
54 }
55
57 PendingJitVariables.emplace_back(RC);
58 }
59
60 // The LambdaType input argument is created as a global variable in the
61 // ProteusPass, thus it has program-wide lifetime. Hence it is valid for
62 // LambdaTypeRef to store a reference to it.
63 inline void registerLambda(const char *LambdaType) {
65 PROTEUS_DBG(Logger::logs("proteus")
66 << "=> RegisterLambda " << LambdaTypeRef << "\n");
67 // Copy PendingJitVariables if there were changed, otherwise the runtime
68 // values for the lambda definition have not changed.
69 if (!PendingJitVariables.empty()) {
70 JitVariableMap[LambdaTypeRef] = PendingJitVariables;
71 PendingJitVariables.clear();
72 }
73 }
74
78
79 bool empty() { return JitVariableMap.empty(); }
80
81private:
82 explicit LambdaRegistry() = default;
83 SmallVector<RuntimeConstant> PendingJitVariables;
85};
86
87} // namespace proteus
88
89#endif
#define PROTEUS_DBG(x)
Definition Debug.h:9
static Config & get()
Definition Config.hpp:304
Definition LambdaRegistry.hpp:20
void registerLambda(const char *LambdaType)
Definition LambdaRegistry.hpp:63
void pushJitVariable(RuntimeConstant &RC)
Definition LambdaRegistry.hpp:56
std::optional< DenseMap< StringRef, SmallVector< RuntimeConstant > >::iterator > matchJitVariableMap(StringRef FnName)
Definition LambdaRegistry.hpp:28
const SmallVector< RuntimeConstant > & getJitVariables(StringRef LambdaTypeRef)
Definition LambdaRegistry.hpp:75
static LambdaRegistry & instance()
Definition LambdaRegistry.hpp:22
bool empty()
Definition LambdaRegistry.hpp:79
static llvm::raw_ostream & logs(const std::string &Name)
Definition Logger.hpp:19
Definition Helpers.h:138
Definition BuiltinsCUDA.cpp:4
T getRuntimeConstantValue(void *Arg)
Definition CompilerInterfaceRuntimeConstantInfo.h:114
Definition CompilerInterfaceTypes.h:72