diff options
Diffstat (limited to 'clang/lib/Serialization/InMemoryModuleCache.cpp')
-rw-r--r-- | clang/lib/Serialization/InMemoryModuleCache.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/clang/lib/Serialization/InMemoryModuleCache.cpp b/clang/lib/Serialization/InMemoryModuleCache.cpp index 68d9411..d35fa2a 100644 --- a/clang/lib/Serialization/InMemoryModuleCache.cpp +++ b/clang/lib/Serialization/InMemoryModuleCache.cpp @@ -11,6 +11,16 @@ using namespace clang; +InMemoryModuleCache::State +InMemoryModuleCache::getPCMState(llvm::StringRef Filename) const { + auto I = PCMs.find(Filename); + if (I == PCMs.end()) + return Unknown; + if (I->second.IsFinal) + return Final; + return I->second.Buffer ? Tentative : ToBuild; +} + llvm::MemoryBuffer & InMemoryModuleCache::addPCM(llvm::StringRef Filename, std::unique_ptr<llvm::MemoryBuffer> Buffer) { @@ -20,11 +30,11 @@ InMemoryModuleCache::addPCM(llvm::StringRef Filename, } llvm::MemoryBuffer & -InMemoryModuleCache::addFinalPCM(llvm::StringRef Filename, +InMemoryModuleCache::addBuiltPCM(llvm::StringRef Filename, std::unique_ptr<llvm::MemoryBuffer> Buffer) { auto &PCM = PCMs[Filename]; assert(!PCM.IsFinal && "Trying to override finalized PCM?"); - assert(!PCM.Buffer && "Already has a non-final PCM"); + assert(!PCM.Buffer && "Trying to override tentative PCM?"); PCM.Buffer = std::move(Buffer); PCM.IsFinal = true; return *PCM.Buffer; @@ -39,21 +49,24 @@ InMemoryModuleCache::lookupPCM(llvm::StringRef Filename) const { } bool InMemoryModuleCache::isPCMFinal(llvm::StringRef Filename) const { - auto I = PCMs.find(Filename); - if (I == PCMs.end()) - return false; - return I->second.IsFinal; + return getPCMState(Filename) == Final; +} + +bool InMemoryModuleCache::shouldBuildPCM(llvm::StringRef Filename) const { + return getPCMState(Filename) == ToBuild; } -bool InMemoryModuleCache::tryToRemovePCM(llvm::StringRef Filename) { +bool InMemoryModuleCache::tryToDropPCM(llvm::StringRef Filename) { auto I = PCMs.find(Filename); assert(I != PCMs.end() && "PCM to remove is unknown..."); auto &PCM = I->second; + assert(PCM.Buffer && "PCM to remove is scheduled to be built..."); + if (PCM.IsFinal) return true; - PCMs.erase(I); + PCM.Buffer.reset(); return false; } |