[llvm-branch-commits] [llvm] cef34cb - address reviewers comments
Yuanfang Chen via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Dec 2 15:25:55 PST 2019
Author: Yuanfang Chen
Date: 2019-11-05T12:23:03-08:00
New Revision: cef34cb7eb9c1ab60b5e0c29e13221df8f1dc52d
URL: https://github.com/llvm/llvm-project/commit/cef34cb7eb9c1ab60b5e0c29e13221df8f1dc52d
DIFF: https://github.com/llvm/llvm-project/commit/cef34cb7eb9c1ab60b5e0c29e13221df8f1dc52d.diff
LOG: address reviewers comments
Added:
Modified:
lld/ELF/Driver.cpp
llvm/include/llvm/LTO/LTO.h
llvm/lib/LTO/LTO.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 0f5f63093633..8ac3e80b93ba 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -192,18 +192,15 @@ std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(
void LinkerDriver::addFile(StringRef path, bool withLOption) {
using namespace sys::fs;
- MemoryBufferRef mbref;
- MemoryBufferRef *MB = nullptr;
+ Optional<MemoryBufferRef> buffer;
if (irSymTabCache)
- MB = irSymTabCache->getMemBufferForPath(path);
- if (MB) {
- mbref = *MB;
- } else {
- Optional<MemoryBufferRef> buffer = readFile(path);
- if (!buffer.hasValue())
- return;
- mbref = *buffer;
- }
+ buffer = irSymTabCache->getMemBufferForPath(path);
+ if (!buffer.hasValue())
+ buffer = readFile(path);
+ if (!buffer.hasValue())
+ return;
+
+ MemoryBufferRef mbref = *buffer;
if (config->formatBinary) {
files.push_back(make<BinaryFile>(mbref));
diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h
index ea86ecb90452..ad7aa737ecc9 100644
--- a/llvm/include/llvm/LTO/LTO.h
+++ b/llvm/include/llvm/LTO/LTO.h
@@ -118,10 +118,10 @@ class IRSymtabFileCache {
public:
IRSymtabFileCache()
: ThinLTOParallelismLevel(std::thread::hardware_concurrency()),
- BackendThreadPool(ThinLTOParallelismLevel) {}
+ BackendThreadPool(ThinLTOParallelismLevel), Cache(), LoadedFiles() {}
void upgrade(const std::vector<std::string> &Files, AddFileFn AFF);
object::IRSymtabFile *get(const MemoryBufferRef &M);
- MemoryBufferRef *getMemBufferForPath(StringRef Path);
+ Optional<MemoryBufferRef> getMemBufferForPath(StringRef Path);
};
/// An input file. This is a symbol table wrapper that only exposes the
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index e2cc99fb94e0..1d75c351fdcc 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1395,8 +1395,8 @@ void IRSymtabFileCache::upgrade(const std::vector<std::string> &Files,
for (auto &F : Files)
AFF(F, LoadedFiles, MBrefs);
- // Cache IR SymTab only if it needs upgrade. Also try to balance the amount
- // work each thread will do based on aggregate MemoryBufferRef size.
+ // Cache IR SymTab only if it needs to be upgraded. Also try to balance the
+ // amount work each thread will do based on aggregate MemoryBufferRef size.
std::vector<MemoryBufferRef> ToCache;
unsigned TotalBufSize = 0;
for (auto &M : MBrefs)
@@ -1406,7 +1406,7 @@ void IRSymtabFileCache::upgrade(const std::vector<std::string> &Files,
Cache.try_emplace(M, nullptr);
}
- if (!ToCache.size())
+ if (ToCache.size() == 0)
return;
// If too few symtabs to cache, assign one to each thread.
@@ -1434,22 +1434,22 @@ void IRSymtabFileCache::upgrade(const std::vector<std::string> &Files,
continue;
CurTotal = 0;
- auto TI = I;
- BackendThreadPool.async(PreLoad, CI, ++TI);
- CI = TI;
+ BackendThreadPool.async(PreLoad, CI, I + 1);
+ CI = I + 1;
if (++NumThread == (ThinLTOParallelismLevel - 1)) {
- BackendThreadPool.async(PreLoad, CI, ToCache.end());
+ BackendThreadPool.async(PreLoad, CI, E);
break;
}
}
BackendThreadPool.wait();
}
-MemoryBufferRef *IRSymtabFileCache::getMemBufferForPath(StringRef Path) {
+Optional<MemoryBufferRef>
+IRSymtabFileCache::getMemBufferForPath(StringRef Path) {
auto I = LoadedFiles.find(Path);
if (I != LoadedFiles.end())
- return &I->second;
- return nullptr;
+ return I->second;
+ return None;
}
Expected<std::unique_ptr<ToolOutputFile>>
More information about the llvm-branch-commits
mailing list