LLVM: include/llvm/ExecutionEngine/Orc/TaskDispatch.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_TASKDISPATCH_H
14#define LLVM_EXECUTIONENGINE_ORC_TASKDISPATCH_H
15
16#include "llvm/Config/llvm-config.h"
21
22#include
23#include
24
25#if LLVM_ENABLE_THREADS
26#include <condition_variable>
27#include
28#include
29#include
30#endif
31
32namespace llvm {
33namespace orc {
34
35
37public:
39
40 ~Task() override = default;
41
42
44
45
47
48private:
49 void anchor() override;
50};
51
52
58
59
61public:
63 : Fn(std::forward<FnT>(Fn)), Desc(DescBuffer.c_str()),
64 DescBuffer(std::move(DescBuffer)) {}
66 : Fn(std::forward<FnT>(Fn)), Desc(Desc) {
67 assert(Desc && "Description cannot be null");
68 }
70 void run() override { Fn(); }
71
72private:
74 const char *Desc;
75 std::string DescBuffer;
76};
77
78
79template
81 std::string Desc) {
82 return std::make_unique<GenericNamedTaskImpl>(std::forward(Fn),
83 std::move(Desc));
84}
85
86
87template
88std::unique_ptr
92 return std::make_unique<GenericNamedTaskImpl>(std::forward(Fn),
94}
95
96
97
99public:
101
102private:
103 void anchor() override;
104};
105
106
108public:
110
111
112 virtual void dispatch(std::unique_ptr T) = 0;
113
114
116};
117
118
120public:
121 void dispatch(std::unique_ptr T) override;
123};
124
125#if LLVM_ENABLE_THREADS
126
128public:
129 DynamicThreadPoolTaskDispatcher(
130 std::optional<size_t> MaxMaterializationThreads)
131 : MaxMaterializationThreads(MaxMaterializationThreads) {}
132
133 void dispatch(std::unique_ptr T) override;
134 void shutdown() override;
135private:
136 bool canRunMaterializationTaskNow();
137 bool canRunIdleTaskNow();
138
139 std::mutex DispatchMutex;
140 bool Shutdown = false;
141 size_t Outstanding = 0;
142 std::condition_variable OutstandingCV;
143
144 std::optional<size_t> MaxMaterializationThreads;
145 size_t NumMaterializationThreads = 0;
146 std::deque<std::unique_ptr> MaterializationTaskQueue;
147 std::deque<std::unique_ptr> IdleTaskQueue;
148};
149
150#endif
151
152}
153}
154
155#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Inheritance utility for extensible RTTI.
GenericNamedTaskImpl(FnT &&Fn, const char *Desc)
Definition TaskDispatch.h:65
void run() override
Definition TaskDispatch.h:70
GenericNamedTaskImpl(FnT &&Fn, std::string DescBuffer)
Definition TaskDispatch.h:62
void printDescription(raw_ostream &OS) override
Definition TaskDispatch.h:69
Base class for generic tasks.
Definition TaskDispatch.h:53
static LLVM_ABI char ID
Definition TaskDispatch.h:55
static LLVM_ABI const char * DefaultDescription
Definition TaskDispatch.h:56
IdleTask can be used as the basis for low-priority tasks, e.g.
Definition TaskDispatch.h:98
static char ID
Definition TaskDispatch.h:100
Runs all tasks on the current thread.
Definition TaskDispatch.h:119
void shutdown() override
Called by ExecutionSession. Waits until all tasks have completed.
void dispatch(std::unique_ptr< Task > T) override
Run the given task.
Abstract base for classes that dispatch ORC Tasks.
Definition TaskDispatch.h:107
virtual void shutdown()=0
Called by ExecutionSession. Waits until all tasks have completed.
virtual void dispatch(std::unique_ptr< Task > T)=0
Run the given task.
virtual ~TaskDispatcher()
Represents an abstract task for ORC to run.
Definition TaskDispatch.h:36
static char ID
Definition TaskDispatch.h:38
virtual void run()=0
Run the task.
virtual void printDescription(raw_ostream &OS)=0
Description of the task to be performed. Used for logging.
This class implements an extremely fast bulk output stream that can only output to a stream.
std::unique_ptr< GenericNamedTask > makeGenericNamedTask(FnT &&Fn, std::string Desc)
Create a generic named task from a std::string description.
Definition TaskDispatch.h:80
This is an optimization pass for GlobalISel generic memory operations.
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.