LibJSGCVerifier: Support message passing between Clang processes

This allows each Clang process to send JSON messages to the
orchestrating Python process, which aggregates the message and can do
something with them all at the end. This is required because we run
Clang multithreaded to speed up the tool execution.

I did try to add a second frontend tool that accepts all the files at
once, but it was _extremely_ slow, so this is the next best thing.
This commit is contained in:
Matthew Olsson 2024-04-06 09:42:14 -07:00 committed by Andreas Kling
parent edf484a5ab
commit dfce95ab0f
Notes: sideshowbarker 2024-07-17 05:41:34 +09:00
3 changed files with 16 additions and 20 deletions

View file

@ -124,20 +124,6 @@ CollectCellsHandler::CollectCellsHandler()
this);
}
bool CollectCellsHandler::handleBeginSource(clang::CompilerInstance& ci)
{
auto const& source_manager = ci.getSourceManager();
auto file_id = source_manager.getMainFileID();
auto const* file_entry = source_manager.getFileEntryForID(file_id);
if (!file_entry)
return false;
auto current_filepath = std::filesystem::canonical(file_entry->getName().str());
llvm::outs() << "Processing " << current_filepath.string() << "\n";
return true;
}
bool record_inherits_from_cell(clang::CXXRecordDecl const& record)
{
if (!record.isCompleteDefinition())

View file

@ -18,8 +18,6 @@ public:
CollectCellsHandler();
virtual ~CollectCellsHandler() override = default;
virtual bool handleBeginSource(clang::CompilerInstance&) override;
virtual void run(clang::ast_matchers::MatchFinder::MatchResult const& result) override;
clang::ast_matchers::MatchFinder& finder() { return m_finder; }

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3
import argparse
import json
import multiprocessing
import os
from pathlib import Path
@ -69,14 +70,25 @@ def thread_execute(file_path):
compile_commands_path,
file_path
]
proc = subprocess.Popen(clang_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
sys.stdout.buffer.write(proc.communicate()[0])
sys.stdout.buffer.flush()
proc = subprocess.Popen(clang_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
print(f'Processed {file_path.resolve()}')
if stderr:
print(stderr.decode(), file=sys.stderr)
results = []
if stdout:
for line in stdout.split(b'\n'):
if line:
results.append(json.loads(line))
return results
with multiprocessing.Pool(processes=multiprocessing.cpu_count() - 2, initializer=thread_init) as pool:
try:
pool.map(thread_execute, paths)
clang_results = []
for results in pool.map(thread_execute, paths):
clang_results.extend(results)
except KeyboardInterrupt:
pool.terminate()
pool.join()