2121#include " llvm/Support/Allocator.h"
2222#include " llvm/Support/CommandLine.h"
2323#include " llvm/Support/StringSaver.h"
24+ #include " llvm/Support/ThreadPool.h"
2425
2526using namespace llvm ;
2627
@@ -39,6 +40,9 @@ llvm::cl::opt<std::string> CASID("id", llvm::cl::desc("<casid>"),
3940 llvm::cl::cat(Category));
4041llvm::cl::opt<std::string> Input (" input" , llvm::cl::desc(" <file|index>" ),
4142 llvm::cl::cat(Category));
43+ llvm::cl::opt<unsigned > Threads (" threads" ,
44+ llvm::cl::desc (" <number of threads>" ),
45+ llvm::cl::cat(Category), cl::init(1 ));
4246llvm::cl::opt<Actions>
4347 Action (" action" , llvm::cl::desc(" <action>" ),
4448 llvm::cl::values(clEnumVal(compute_cache_key, " compute cache key" ),
@@ -216,16 +220,27 @@ int main(int argc, char *argv[]) {
216220 llvm::StringSaver Saver (Alloc);
217221 auto Args = createArgs (SwiftCommands, Saver);
218222
219- switch (Action) {
220- case compute_cache_key:
221- return action_compute_cache_key (cas, Input, Args);
222- case compute_cache_key_from_index:
223- return action_compute_cache_key_from_index (cas, Input, Args);
224- case cache_query:
225- return action_cache_query (cas, CASID.c_str ());
226- case replay_result:
227- return action_replay_result (cas, CASID.c_str (), Args);
223+ std::atomic<int > Ret = 0 ;
224+ llvm::ThreadPool Pool (llvm::hardware_concurrency (Threads));
225+ for (unsigned i = 0 ; i < Threads; ++i) {
226+ Pool.async ([&]() {
227+ switch (Action) {
228+ case compute_cache_key:
229+ Ret += action_compute_cache_key (cas, Input, Args);
230+ break ;
231+ case compute_cache_key_from_index:
232+ Ret += action_compute_cache_key_from_index (cas, Input, Args);
233+ break ;
234+ case cache_query:
235+ Ret += action_cache_query (cas, CASID.c_str ());
236+ break ;
237+ case replay_result:
238+ Ret += action_replay_result (cas, CASID.c_str (), Args);
239+ break ;
240+ }
241+ });
228242 }
243+ Pool.wait ();
229244
230- return EXIT_SUCCESS ;
245+ return Ret ;
231246}
0 commit comments