LLVM  14.0.0git
TaskDispatch.cpp
Go to the documentation of this file.
1 //===------------ TaskDispatch.cpp - ORC task dispatch utils --------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 namespace llvm {
12 namespace orc {
13 
14 char Task::ID = 0;
15 char GenericNamedTask::ID = 0;
16 const char *GenericNamedTask::DefaultDescription = "Generic Task";
17 
18 void Task::anchor() {}
20 
21 void InPlaceTaskDispatcher::dispatch(std::unique_ptr<Task> T) { T->run(); }
22 
24 
25 #if LLVM_ENABLE_THREADS
26 void DynamicThreadPoolTaskDispatcher::dispatch(std::unique_ptr<Task> T) {
27  {
28  std::lock_guard<std::mutex> Lock(DispatchMutex);
29  ++Outstanding;
30  }
31 
32  std::thread([this, T = std::move(T)]() mutable {
33  T->run();
34  std::lock_guard<std::mutex> Lock(DispatchMutex);
35  --Outstanding;
36  OutstandingCV.notify_all();
37  }).detach();
38 }
39 
41  std::unique_lock<std::mutex> Lock(DispatchMutex);
42  Running = false;
43  OutstandingCV.wait(Lock, [this]() { return Outstanding == 0; });
44 }
45 #endif
46 
47 } // namespace orc
48 } // namespace llvm
llvm::orc::Task::ID
static char ID
Definition: TaskDispatch.h:36
llvm::orc::InPlaceTaskDispatcher::shutdown
void shutdown() override
Called by ExecutionSession. Waits until all tasks have completed.
Definition: TaskDispatch.cpp:23
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::orc::InPlaceTaskDispatcher::dispatch
void dispatch(std::unique_ptr< Task > T) override
Run the given task.
Definition: TaskDispatch.cpp:21
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::orc::GenericNamedTask::ID
static char ID
Definition: TaskDispatch.h:53
llvm::Lock
static sys::Mutex Lock
Definition: NVPTXUtilities.cpp:39
llvm::orc::GenericNamedTask::DefaultDescription
static const char * DefaultDescription
Definition: TaskDispatch.h:54
llvm::orc::DynamicThreadPoolTaskDispatcher::shutdown
void shutdown() override
Called by ExecutionSession. Waits until all tasks have completed.
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::orc::DynamicThreadPoolTaskDispatcher::dispatch
void dispatch(std::unique_ptr< Task > T) override
Run the given task.
TaskDispatch.h
llvm::orc::TaskDispatcher::~TaskDispatcher
virtual ~TaskDispatcher()
Definition: TaskDispatch.cpp:19