5 #ifndef CLEARBLUE_BOTUPPARALLELPASS_H
6 #define CLEARBLUE_BOTUPPARALLELPASS_H
8 #include <condition_variable>
9 #include <llvm/IR/Function.h>
10 #include <llvm/IR/Module.h>
11 #include <llvm/Pass.h>
15 #include "Analysis/CallGraph/CBCallGraph.h"
16 #include "IR/SEG/SymbolicExprGraphBuilder.h"
17 #include "Utils/ProgressBar.h"
27 std::set<TaskDepVertex *> Parents;
30 std::set<TaskDepVertex *> InternalChildren;
31 std::set<TaskDepVertex *> ExternalChildren;
38 InternalChildren.insert(T);
39 T->Parents.insert(
this);
44 ExternalChildren.insert(T);
45 T->Parents.insert(
this);
48 std::set<TaskDepVertex *>::iterator
49 removeParent(std::set<TaskDepVertex *>::iterator It) {
51 (*It)->ExternalChildren.erase(
this);
53 (*It)->InternalChildren.erase(
this);
55 return Parents.erase(It);
60 T->ExternalChildren.erase(
this);
62 T->InternalChildren.erase(
this);
69 return ExternalChildren.count(T);
71 return InternalChildren.count(T);
74 size_t getIndex() {
return Index; }
76 Function *getFunction() {
return F; }
80 std::set<TaskDepVertex *> &InternalChildren;
81 std::set<TaskDepVertex *> &ExternalChildren;
83 std::set<TaskDepVertex *>::iterator It;
87 std::set<TaskDepVertex *> &ExternalChildren,
bool Begin)
88 : InternalChildren(InternalChildren),
89 ExternalChildren(ExternalChildren) {
91 It = InternalChildren.begin();
92 if (It == InternalChildren.end())
93 It = ExternalChildren.begin();
95 It = ExternalChildren.end();
100 : InternalChildren(ChildrenIt.InternalChildren),
101 ExternalChildren(ChildrenIt.ExternalChildren), It(ChildrenIt.It) {}
105 if (It == InternalChildren.end()) {
106 It = ExternalChildren.begin();
124 std::set<TaskDepVertex *>::iterator internal_children_begin() {
125 return InternalChildren.begin();
128 std::set<TaskDepVertex *>::iterator internal_children_end() {
129 return InternalChildren.end();
132 bool internal_children_empty() {
return InternalChildren.empty(); }
134 std::set<TaskDepVertex *>::iterator external_children_begin() {
135 return ExternalChildren.begin();
138 std::set<TaskDepVertex *>::iterator external_children_end() {
139 return ExternalChildren.end();
142 bool external_children_empty() {
return ExternalChildren.empty(); }
144 ChildrenIterator children_begin() {
145 return ChildrenIterator(InternalChildren, ExternalChildren,
true);
148 ChildrenIterator children_end() {
149 return ChildrenIterator(InternalChildren, ExternalChildren,
false);
152 bool children_empty() {
153 return internal_children_empty() && external_children_empty();
156 std::set<TaskDepVertex *>::iterator parents_begin() {
157 return Parents.begin();
160 std::set<TaskDepVertex *>::iterator parents_end() {
return Parents.end(); }
165 std::vector<TaskDepVertex *> Vertices;
171 for (
auto *V : Vertices) {
178 std::vector<TaskDepVertex *>::iterator begin() {
return Vertices.begin(); }
180 std::vector<TaskDepVertex *>::iterator end() {
return Vertices.end(); }
182 size_t size() {
return Vertices.size(); }
184 const std::vector<TaskDepVertex *> &getVertices() {
return Vertices; }
189 unsigned NumTasksEachFunc;
193 std::condition_variable Cond;
194 std::vector<TaskDepVertex *> FinishedTasks;
195 std::map<Function *, unsigned> FunctionIndegreeMap;
198 CBCallGraph *CG =
nullptr;
203 : ModulePass(ID), NumTasksEachFunc(NumTasks),
204 Prog(
"[Sailfish Checking]", ProgressBar::PBS_CharacterStyle) {}
208 virtual void getAnalysisUsage(AnalysisUsage &AU)
const override;
210 virtual bool runOnModule(Module &M)
override;
212 virtual bool runOnFunction(Function &F) = 0;
222 virtual bool runOnFunction(Function &F,
unsigned TaskID) = 0;
227 virtual bool releaseMemory(Function &F) = 0;
231 virtual bool internallyDepends(
unsigned TaskAID,
unsigned TaskBID) = 0;
235 virtual bool externallyDepends(
unsigned CallerTaskID,
236 unsigned CalleeTaskID) = 0;
239 if (Func && Func->hasName() &&
240 Func->getName().startswith(
"Pinpoint.CondExit.")) {
243 return Func && !Func->isIntrinsic() && !Func->isDeclaration();
247 void buildTaskDependenceGraph(
TaskDepGraph &TDG, CBCallGraph &CG, Module &M);
249 void buildDepsTemplate(std::vector<TaskDepVertex *> &Tasks);
252 std::vector<TaskDepVertex *> &Tasks,
253 std::vector<TaskDepVertex *> &Templates);
255 void buildExternalDeps(std::vector<TaskDepVertex *> &CallerTasks,
256 std::vector<TaskDepVertex *> &CalleeTasks,
257 std::vector<TaskDepVertex *> &Templates);
268 #endif // CLEARBLUE_BOTUPPARALLELPASS_H