diff options
Diffstat (limited to 'llvm/tools/llvm-cov/CodeCoverage.cpp')
-rw-r--r-- | llvm/tools/llvm-cov/CodeCoverage.cpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 5f1e23f20d772..b3c895b44a6d6 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -33,6 +33,7 @@ #include "llvm/Support/Process.h" #include "llvm/Support/Program.h" #include "llvm/Support/ScopedPrinter.h" +#include "llvm/Support/SpecialCaseList.h" #include "llvm/Support/ThreadPool.h" #include "llvm/Support/Threading.h" #include "llvm/Support/ToolOutputFile.h" @@ -245,7 +246,8 @@ CodeCoverageTool::getSourceFile(StringRef SourceFile) { error(EC.message(), SourceFile); return EC; } - LoadedSourceFiles.emplace_back(SourceFile, std::move(Buffer.get())); + LoadedSourceFiles.emplace_back(std::string(SourceFile), + std::move(Buffer.get())); return *LoadedSourceFiles.back().second; } @@ -413,7 +415,8 @@ void CodeCoverageTool::remapPathNames(const CoverageMapping &Coverage) { // Convert input files from local paths to coverage data file paths. StringMap<std::string> InvRemappedFilenames; for (const auto &RemappedFilename : RemappedFilenames) - InvRemappedFilenames[RemappedFilename.getValue()] = RemappedFilename.getKey(); + InvRemappedFilenames[RemappedFilename.getValue()] = + std::string(RemappedFilename.getKey()); for (std::string &Filename : SourceFiles) { SmallString<128> NativeFilename; @@ -510,7 +513,7 @@ void CodeCoverageTool::demangleSymbols(const CoverageMapping &Coverage) { for (const auto &Function : Coverage.getCoveredFunctions()) // On Windows, lines in the demangler's output file end with "\r\n". // Splitting by '\n' keeps '\r's, so cut them now. - DC.DemangledNames[Function.Name] = Symbols[I++].rtrim(); + DC.DemangledNames[Function.Name] = std::string(Symbols[I++].rtrim()); } void CodeCoverageTool::writeSourceFileView(StringRef SourceFile, @@ -688,7 +691,8 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { // PathRemapping. auto EquivPair = StringRef(PathRemap).split(','); if (!(EquivPair.first.empty() && EquivPair.second.empty())) - PathRemapping = EquivPair; + PathRemapping = {std::string(EquivPair.first), + std::string(EquivPair.second)}; // If a demangler is supplied, check if it exists and register it. if (!DemanglerOpts.empty()) { @@ -864,8 +868,8 @@ int CodeCoverageTool::doShow(int argc, const char **argv, } sys::fs::file_status Status; - if (sys::fs::status(PGOFilename, Status)) { - error("profdata file error: can not get the file status. \n"); + if (std::error_code EC = sys::fs::status(PGOFilename, Status)) { + error("Could not read profile data!", EC.message()); return 1; } @@ -886,7 +890,7 @@ int CodeCoverageTool::doShow(int argc, const char **argv, // Get the source files from the function coverage mapping. for (StringRef Filename : Coverage->getUniqueSourceFiles()) { if (!IgnoreFilenameFilters.matchesFilename(Filename)) - SourceFiles.push_back(Filename); + SourceFiles.push_back(std::string(Filename)); } // Create an index out of the source files. @@ -940,21 +944,21 @@ int CodeCoverageTool::doShow(int argc, const char **argv, (SourceFiles.size() != 1) || ViewOpts.hasOutputDirectory() || (ViewOpts.Format == CoverageViewOptions::OutputFormat::HTML); - auto NumThreads = ViewOpts.NumThreads; - - // If NumThreads is not specified, auto-detect a good default. - if (NumThreads == 0) - NumThreads = - std::max(1U, std::min(llvm::heavyweight_hardware_concurrency(), - unsigned(SourceFiles.size()))); + ThreadPoolStrategy S = hardware_concurrency(ViewOpts.NumThreads); + if (ViewOpts.NumThreads == 0) { + // If NumThreads is not specified, create one thread for each input, up to + // the number of hardware cores. + S = heavyweight_hardware_concurrency(SourceFiles.size()); + S.Limit = true; + } - if (!ViewOpts.hasOutputDirectory() || NumThreads == 1) { + if (!ViewOpts.hasOutputDirectory() || S.ThreadsRequested == 1) { for (const std::string &SourceFile : SourceFiles) writeSourceFileView(SourceFile, Coverage.get(), Printer.get(), ShowFilenames); } else { // In -output-dir mode, it's safe to use multiple threads to print files. - ThreadPool Pool(NumThreads); + ThreadPool Pool(S); for (const std::string &SourceFile : SourceFiles) Pool.async(&CodeCoverageTool::writeSourceFileView, this, SourceFile, Coverage.get(), Printer.get(), ShowFilenames); |