| 25 | namespace impala { |
| 26 | |
| 27 | void CodeGenObjectCache::notifyObjectCompiled( |
| 28 | const llvm::Module* M, llvm::MemoryBufferRef ObjBuffer) { |
| 29 | DCHECK(M != nullptr); |
| 30 | // Save the compiled object in the memory cache, with the module ID as the key. |
| 31 | // In our scenario, we anticipate having only one module per execution engine. |
| 32 | // Consequently, each CodeGenObjectCache should hold just one module. |
| 33 | // If a module with a different ID is encountered, a warning is logged for |
| 34 | // further investigation. |
| 35 | const string& module_id = M->getModuleIdentifier(); |
| 36 | std::lock_guard<std::mutex> l(mutex_); |
| 37 | if (key_.empty()) { |
| 38 | LOG(INFO) << "Insert module id " << module_id << " in CodeGenObjectCache " << this |
| 39 | << " with size " << ObjBuffer.getBuffer().size() << " bytes"; |
| 40 | key_ = module_id; |
| 41 | // The Buffer Id doesn't seem to serve a purpose in our case, and skipping it |
| 42 | // can conserve memory. |
| 43 | cached_obj_ = |
| 44 | llvm::MemoryBuffer::getMemBufferCopy(ObjBuffer.getBuffer(), "" /*Buffer Id*/); |
| 45 | } else if (key_ != module_id) { |
| 46 | stringstream ss; |
| 47 | ss << "Inserting a different module in CodeGenObjectCache " << this |
| 48 | << ". Old module id is " << module_id << ", and new module id is " << key_; |
| 49 | DCHECK(false) << ss.str(); |
| 50 | LOG(WARNING) << ss.str(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | std::unique_ptr<llvm::MemoryBuffer> CodeGenObjectCache::getObject(const llvm::Module* M) { |
| 55 | DCHECK(M != nullptr); |