@@ -31,15 +31,55 @@ SPDX-License-Identifier: MIT
31
31
#include " llvm/Support/raw_ostream.h"
32
32
#include " llvm/Transforms/Utils/Cloning.h"
33
33
#include " llvm/Transforms/Utils/ValueMapper.h"
34
- using namespace llvm ;
34
+
35
+ #include " GenXUtil.h"
35
36
36
37
#include " llvmWrapper/IR/LegacyPassManagers.h"
37
38
#include " llvmWrapper/IR/PassTimingInfo.h"
38
- #include " Probe/Assertion.h"
39
39
40
+ #include " Probe/Assertion.h"
40
41
41
42
#define DEBUG_TYPE " functiongroup-passmgr"
42
43
44
+ using namespace llvm ;
45
+
46
+ bool FunctionGroup::verify () const {
47
+ for (auto I = Functions.begin (), E = Functions.end (); I != E; ++I) {
48
+ Function *F = &(**I);
49
+ for (auto *U : F->users ()) {
50
+ auto *CI = genx::checkFunctionCall (U, F);
51
+ if (!CI)
52
+ continue ;
53
+
54
+ // Note: it is expected that all users of any function from
55
+ // Functions array belong to the same FG
56
+ Function *Caller = CI->getFunction ();
57
+ auto *OtherGroup = FGA->getAnyGroup (Caller);
58
+ IGC_ASSERT_MESSAGE (OtherGroup == this ,
59
+ " inconsisten function group detected!" );
60
+ if (OtherGroup != this )
61
+ return false ;
62
+ }
63
+ }
64
+ return true ;
65
+ }
66
+
67
+ #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
68
+ void FunctionGroup::print (raw_ostream &OS) const {
69
+ OS << " {{{" << getName () << " }}}\n " ;
70
+ for (const Function *F : Functions) {
71
+ OS << " " << F->getName () << " \n " ;
72
+ }
73
+
74
+ for (const auto &EnItem : enumerate(Subgroups)) {
75
+ OS << " --SGR[" << EnItem.index () << " ]: " ;
76
+ OS << " <" << EnItem.value ()->getHead ()->getName () << " >]\n " ;
77
+ }
78
+ }
79
+
80
+ void FunctionGroup::dump () const { print (dbgs ()); }
81
+ #endif // if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
82
+
43
83
/* **********************************************************************
44
84
* FunctionGroupAnalysis implementation
45
85
*/
@@ -57,13 +97,9 @@ void FunctionGroupAnalysis::clear() {
57
97
for (auto T : TypesToProcess)
58
98
GroupMap[T].clear ();
59
99
60
- for (auto i = begin (), e = end (); i != e; ++i)
61
- delete *i;
62
- for (auto i = NonMainGroups.begin (), e = NonMainGroups.end (); i != e; ++i)
63
- delete *i;
64
-
65
100
Groups.clear ();
66
101
NonMainGroups.clear ();
102
+ Visited.clear ();
67
103
M = nullptr ;
68
104
}
69
105
@@ -140,11 +176,12 @@ void FunctionGroupAnalysis::addToFunctionGroup(FunctionGroup *FG, Function *F,
140
176
// createFunctionGroup : create new FunctionGroup for which F is the head
141
177
FunctionGroup *FunctionGroupAnalysis::createFunctionGroup (Function *F,
142
178
FGType Type) {
143
- auto FG = new FunctionGroup (this );
179
+ auto *FG = new FunctionGroup (this );
180
+ auto FGOwner = std::unique_ptr<FunctionGroup>(FG);
144
181
if (Type == FGType::GROUP)
145
- Groups.push_back (FG );
182
+ Groups.push_back (std::move (FGOwner) );
146
183
else
147
- NonMainGroups.push_back (FG );
184
+ NonMainGroups.push_back (std::move (FGOwner) );
148
185
addToFunctionGroup (FG, F, Type);
149
186
return FG;
150
187
}
@@ -211,7 +248,7 @@ bool FunctionGroupAnalysis::buildGroup(CallGraph &Callees, Function *F,
211
248
}
212
249
}
213
250
} else if (!Visited.count (F)) {
214
- Visited[F] = true ;
251
+ Visited. insert (F) ;
215
252
// group is created either on a function with a corresponding attribute
216
253
// or on a root of a whole function tree that is kernel (genx_main)
217
254
if (F->hasFnAttribute (TypeToAttr (Type)) ||
@@ -240,6 +277,30 @@ bool FunctionGroupAnalysis::buildGroup(CallGraph &Callees, Function *F,
240
277
return result;
241
278
}
242
279
280
+ bool FunctionGroupAnalysis::verify () const {
281
+ return std::all_of (Groups.begin (), Groups.end (),
282
+ [](const auto &GR) { return GR->verify (); });
283
+ }
284
+
285
+ #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
286
+ void FunctionGroupAnalysis::print (raw_ostream &OS) const {
287
+ OS << " Number of Groups = " << Groups.size () << " \n " ;
288
+ for (const auto &X : enumerate(Groups)) {
289
+ OS << " GR[" << X.index () << " ] = <\n " ;
290
+ X.value ()->print (OS);
291
+ OS << " >\n " ;
292
+ }
293
+ OS << " Number of SubGroups = " << NonMainGroups.size () << " \n " ;
294
+ for (const auto &X : enumerate(NonMainGroups)) {
295
+ OS << " SGR[" << X.index () << " ] = <\n " ;
296
+ X.value ()->print (OS);
297
+ OS << " >\n " ;
298
+ }
299
+ }
300
+
301
+ void FunctionGroupAnalysis::dump () const { print (dbgs ()); }
302
+ #endif // if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
303
+
243
304
// ===----------------------------------------------------------------------===//
244
305
// FGPassManager
245
306
//
0 commit comments