logic: multithreaded parsing

* modified the TaskParseCxx to be able to run multiple times in parallel
* made FileRegister threadsafe and changed a lot of its mechanisms
* added TaskGroupParallel that runs all children in parallel
* added TaskParseWrapper that acts as a decorator to execute some code before and after parsing.
* implemented task setup in project with 4 parsing threads
* removed SimpleTask as it was only used as interface for the LambdaTask
This commit is contained in:
malte_langkabel
2016-05-13 13:23:54 +02:00
parent 245cafdc7b
commit c61efbbcde
27 changed files with 535 additions and 317 deletions
@@ -29,8 +29,3 @@ bool ASTAction::BeginSourceFileAction(clang::CompilerInstance& compiler, llvm::S
preprocessor.addCommentHandler(&m_commentHandler);
return true;
}
void ASTAction::EndSourceFileAction()
{
m_fileRegister->markParsingIncludeFilesParsed();
}
@@ -18,7 +18,6 @@ protected:
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile);
virtual bool BeginSourceFileAction(clang::CompilerInstance& compiler, llvm::StringRef filePath);
virtual void EndSourceFileAction();
private:
ParserClient* m_client;
@@ -1503,7 +1503,7 @@ bool ASTVisitor::isLocatedInUnparsedProjectFile(clang::SourceLocation loc)
{
std::string fileName = fileEntry->getName();
FilePath filePath = FilePath(fileName).canonical();
ret = m_fileRegister->includeFileIsParsing(filePath.str());
ret = m_fileRegister->includeFileIsParsed(filePath.str());
}
}
m_inUnparsedProjectFileMap[fileId] = ret;
+9 -19
View File
@@ -2,7 +2,6 @@
#include "clang/Tooling/Tooling.h"
#include "utility/file/FileManager.h"
#include "utility/file/FileRegister.h"
#include "utility/logging/logging.h"
#include "utility/text/TextAccess.h"
@@ -53,9 +52,9 @@ namespace
}
CxxParser::CxxParser(ParserClient* client, const FileManager* fileManager)
CxxParser::CxxParser(ParserClient* client, std::shared_ptr<FileRegister> fileRegister)
: Parser(client)
, m_fileRegister(std::make_shared<FileRegister>(fileManager))
, m_fileRegister(fileRegister)
{
}
@@ -65,29 +64,22 @@ CxxParser::~CxxParser()
void CxxParser::parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments)
{
setupParsing(filePaths, arguments);
m_fileRegister->setFilePaths(filePaths);
setupParsing(arguments);
std::vector<std::string> sourcePaths;
for (const FilePath& path : m_fileRegister->getUnparsedSourceFilePaths())
for (const FilePath& path : m_fileRegister->getUnparsedSourceFilePaths()) // filter headers
{
sourcePaths.push_back(path.absolute().str());
}
runTool(sourcePaths);
std::vector<FilePath> unparsedHeaders = m_fileRegister->getUnparsedIncludeFilePaths();
for (const FilePath& path : unparsedHeaders)
{
if (!m_fileRegister->includeFileIsParsed(path))
{
runTool(std::vector<std::string>(1, path.str()));
}
}
}
void CxxParser::parseFile(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess, const Arguments& arguments)
{
setupParsing(std::vector<FilePath>(1, filePath), arguments);
m_fileRegister->setFilePaths(std::vector<FilePath>(1, filePath));
setupParsing(arguments);
std::vector<std::string> args = getCommandlineArguments(arguments);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(arguments);
@@ -190,16 +182,14 @@ std::shared_ptr<CxxDiagnosticConsumer> CxxParser::getDiagnostics(const Arguments
llvm::errs(), &*options, m_client, m_fileRegister->getFileManager(), arguments.logErrors);
}
void CxxParser::setupParsing(const std::vector<FilePath>& filePaths, const Arguments& arguments)
void CxxParser::setupParsing(const Arguments& arguments)
{
m_fileRegister->setFilePaths(filePaths);
m_compilationDatabase = getCompilationDatabase(arguments);
m_diagnostics = getDiagnostics(arguments);
}
void CxxParser::setupParsingCDB(const std::vector<FilePath>& filePaths, const Arguments& arguments)
void CxxParser::setupParsingCDB(const Arguments& arguments)
{
m_fileRegister->setFilePaths(filePaths);
m_diagnostics = getDiagnostics(arguments);
}
+4 -4
View File
@@ -5,14 +5,14 @@
#include "data/parser/Parser.h"
class CxxDiagnosticConsumer;
class FileManager;
class FileRegister;
class FileRegister;
class TaskParseCxx;
class CxxParser: public Parser
{
public:
CxxParser(ParserClient* client, const FileManager* fileManager);
CxxParser(ParserClient* client, std::shared_ptr<FileRegister> fileRegister);
~CxxParser();
// ParserClient implementation
@@ -27,8 +27,8 @@ private:
std::shared_ptr<CxxDiagnosticConsumer> getDiagnostics(const Arguments& arguments) const;
// Accessed by TaskParseCxx
void setupParsing(const std::vector<FilePath>& filePaths, const Arguments& arguments);
void setupParsingCDB(const std::vector<FilePath>& filePaths, const Arguments& arguments);
void setupParsing(const Arguments& arguments);
void setupParsingCDB(const Arguments& arguments);
void runTool(const std::vector<std::string>& files);
void runTool(clang::tooling::CompileCommand command, const Arguments& arguments);