11#ifndef PROTEUS_JITCACHE_HPP
12#define PROTEUS_JITCACHE_HPP
23#include <llvm/ADT/DenseMap.h>
24#include <llvm/ADT/SmallVector.h>
25#include <llvm/ADT/StringRef.h>
26#include <llvm/Config/llvm-config.h>
38 auto It = CacheMap.find(HashValue);
39 if (It == CacheMap.end())
42 It->second.NumExecs++;
45 return It->second.FunctionPtr;
49 [[maybe_unused]] StringRef FnName,
50 [[maybe_unused]] ArrayRef<RuntimeConstant> RCArr) {
51#if PROTEUS_ENABLE_DEBUG
52 if (CacheMap.count(HashValue))
56 CacheMap[HashValue] = {FunctionPtr, 1, 0};
58#if PROTEUS_ENABLE_DEBUG
59 CacheMap[HashValue].FnName = FnName.str();
60 CacheMap[HashValue].RCVector = SmallVector<RuntimeConstant>{RCArr};
67 printf(
"JitCache hits %lu total %lu\n", Hits, Accesses);
68 for (
const auto &[HashValue, JCE] : CacheMap) {
69 std::cout <<
"HashValue " << HashValue.toString() <<
" NumExecs "
70 << JCE.NumExecs <<
" NumHits " << JCE.NumHits;
71#if PROTEUS_ENABLE_DEBUG
73 printf(
" FnName %s RCs [", JCE.FnName.c_str());
74 for (
auto &RC : JCE.RCVector)
76 printf(
"%ld, ", RC.Value.Int64Val);
88 struct JitCacheEntry {
89 Function_t FunctionPtr;
92#if PROTEUS_ENABLE_DEBUG
94 SmallVector<RuntimeConstant> RCVector;
98 std::unordered_map<HashT, JitCacheEntry> CacheMap;
102 uint64_t Accesses = 0;
#define PROTEUS_FATAL_ERROR(x)
Definition Error.h:4
#define TIMESCOPE(x)
Definition TimeTracing.hpp:35
Definition Hashing.hpp:19
Definition JitCache.hpp:32
void insert(HashT &HashValue, Function_t FunctionPtr, StringRef FnName, ArrayRef< RuntimeConstant > RCArr)
Definition JitCache.hpp:48
Function_t lookup(HashT &HashValue)
Definition JitCache.hpp:34
void printStats()
Definition JitCache.hpp:64
JitCache()
Definition JitCache.hpp:85
Definition JitEngine.cpp:20