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> RCArray) {
51#if PROTEUS_ENABLE_DEBUG
52 if (CacheMap.count(HashValue))
56 auto &CacheEntry = CacheMap[HashValue];
57 CacheEntry.FunctionPtr = FunctionPtr;
58 CacheEntry.NumExecs = 1;
59 CacheEntry.NumHits = 0;
61#if PROTEUS_ENABLE_DEBUG
62 CacheEntry.FnName = FnName.str();
63 CacheEntry.RCVector = SmallVector<RuntimeConstant>{RCArray};
70 printf(
"JitCache hits %lu total %lu\n", Hits, Accesses);
71 for (
const auto &[HashValue, JCE] : CacheMap) {
72 std::cout <<
"HashValue " << HashValue.toString() <<
" NumExecs "
73 << JCE.NumExecs <<
" NumHits " << JCE.NumHits;
74#if PROTEUS_ENABLE_DEBUG
76 printf(
" FnName %s RCs [", JCE.FnName.c_str());
77 for (
auto &RC : JCE.RCVector)
79 printf(
"%ld, ", RC.Value.Int64Val);
91 struct JitCacheEntry {
92 Function_t FunctionPtr;
95#if PROTEUS_ENABLE_DEBUG
97 SmallVector<RuntimeConstant> RCVector;
101 std::unordered_map<HashT, JitCacheEntry> CacheMap;
105 uint64_t Accesses = 0;
#define PROTEUS_FATAL_ERROR(x)
Definition Error.h:4
#define TIMESCOPE(x)
Definition TimeTracing.hpp:64
Definition Hashing.hpp:19
Definition JitCache.hpp:32
void insert(HashT &HashValue, Function_t FunctionPtr, StringRef FnName, ArrayRef< RuntimeConstant > RCArray)
Definition JitCache.hpp:48
Function_t lookup(HashT &HashValue)
Definition JitCache.hpp:34
void printStats()
Definition JitCache.hpp:67
JitCache()
Definition JitCache.hpp:88
Definition Dispatcher.cpp:14