| 52 | } |
| 53 | |
| 54 | std::unique_ptr<llvm::MemoryBuffer> CodeGenObjectCache::getObject(const llvm::Module* M) { |
| 55 | DCHECK(M != nullptr); |
| 56 | // Return a copy of the cached object containing the compiled module with the specified |
| 57 | // ID. If the ID doesn't match the one in the cached object, a warning is logged for |
| 58 | // further investigation. |
| 59 | const string& module_id = M->getModuleIdentifier(); |
| 60 | std::lock_guard<std::mutex> l(mutex_); |
| 61 | if (module_id == key_) { |
| 62 | LOG(INFO) << "Object for module id " << module_id << " loaded from cache with size " |
| 63 | << cached_obj_->getMemBufferRef().getBufferSize() << " bytes"; |
| 64 | return llvm::MemoryBuffer::getMemBufferCopy( |
| 65 | cached_obj_->getMemBufferRef().getBuffer()); |
| 66 | } else if (!key_.empty()) { |
| 67 | stringstream ss; |
| 68 | ss << "Object for module id " << module_id << " can't be loaded from cache." |
| 69 | << " Existing module id is " << key_; |
| 70 | DCHECK(false) << ss.str(); |
| 71 | LOG(WARNING) << ss.str(); |
| 72 | } |
| 73 | return nullptr; |
| 74 | } |
| 75 | |
| 76 | size_t CodeGenObjectCache::objSize() { |
| 77 | size_t sz = sizeof(CodeGenObjectCache); |
no test coverage detected