-
Notifications
You must be signed in to change notification settings - Fork 3
/
HPCParallelPattern.h
214 lines (132 loc) · 5.2 KB
/
HPCParallelPattern.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#pragma once
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include "clang/AST/Decl.h"
#include "llvm/Support/Casting.h"
#include "DesignSpaces.h"
#include "PatternGraph.h"
/* Forward declarations */
class PatternOccurrence;
class PatternCodeRegion;
/**
* This class describes a parallel pattern identified by the design space and the pattern name.
* The pattern name is not the same as the pattern identifier, as only PatternOccurrence can have an identifier.
* A parallel pattern can have one or multiple PatternOccurrences which are registered in this object.
*/
class HPCParallelPattern
{
public:
HPCParallelPattern(DesignSpace DesignSp, std::string PatternName);
void Print();
void PrintShort();
void AddOccurrence(PatternOccurrence* Occurrence);
std::vector<PatternOccurrence*> GetOccurrences();
std::vector<PatternCodeRegion*> GetCodeRegions();
std::string GetPatternName() { return this->PatternName; }
std::string GetDesignSpaceStr() { return DesignSpaceToStr(this->DesignSp); }
DesignSpace GetDesignSpace() { return DesignSp; }
int GetTotalLinesOfCode();
bool Equals(HPCParallelPattern* Pattern);
void incrementNumOfOperators();
int GetNumOfOperators();
private:
DesignSpace DesignSp;
std::string PatternName;
int numOfOperators = 0;
std::vector<PatternOccurrence*> Occurrences;
};
/**
* The PatternOccurrence is a hypothetical construct that represents a collection for all code regions
* with the same identifier.
* It is linked to a unique HPCParallelPattern.
* Each PatternCodeRegion with this identifier is accessible from this object.
*/
class PatternOccurrence
{
public:
PatternOccurrence(HPCParallelPattern* Pattern, std::string ID);
HPCParallelPattern* GetPattern() { return this->Pattern; }
void Print();
std::string GetID() { return this->ID; }
void AddCodeRegion(PatternCodeRegion* CodeRegion) { this->CodeRegions.push_back(CodeRegion); }
std::vector<PatternCodeRegion*> GetCodeRegions() { return this->CodeRegions; }
int GetTotalLinesOfCode();
int GetNumberOfCodeRegions() { return this->CodeRegions.size(); }
bool Equals(PatternOccurrence* PatternOcc);
private:
HPCParallelPattern* Pattern;
std::vector<PatternCodeRegion*> CodeRegions;
std::string ID;
};
/**
* This class represents a block of code that is enclosed with the instrumentation calls.
* It is a node in the pattern tree, hence has children and parents in the tree.
* A PatternCodeRegion belongs to a PatternOccurrence.
*/
class PatternCodeRegion : public PatternGraphNode
{
public:
~PatternCodeRegion();
PatternCodeRegion(PatternOccurrence* PatternOcc);
PatternOccurrence* GetPatternOccurrence() { return this->PatternOcc; }
static bool classof(const PatternGraphNode* Node)
{
return Node->GetKind() == PatternGraphNode::GNK_Pattern;
}
void Print();
void AddChild(PatternGraphNode* Child);
void AddParent(PatternGraphNode* Parent);
void AddOnlyPatternChild(PatternGraphNode* PatChild);
void AddOnlyPatternParent(PatternGraphNode* PatParent);
std::vector<PatternGraphNode*> GetChildren() { return this->Children; }
std::vector<PatternCodeRegion*> GetOnlyPatternChildren() { return this->PatternChildren; }
std::vector<PatternGraphNode*> GetParents() { return this->Parents; }
std::vector<PatternCodeRegion*> GetOnlyPatternParents() { return this->PatternParents; }
void SetFirstLine (int FirstLine);
void SetLastLine (int LastLine);
void SetStartSourceLoc(clang::SourceLocation StartLoc);
void SetEndSourceLoc(clang::SourceLocation EndLoc);
clang::SourceLocation GetStartLoc();
clang::SourceLocation GetEndLoc();
int GetLinesOfCode() { return this->LinesOfCode; }
std::string GetID() { return this->PatternOcc->GetID(); }
bool HasNoPatternParents();
bool HasNoPatternChildren();
bool isInMain = false;
void PrintVecOfPattern(std::vector<PatternCodeRegion*> RegionVec);
void insertCorrespondingCallTreeNode(CallTreeNode* Node){
CorrespondingCallTreeNodes.push_back(Node);
}
std::vector<CallTreeNode*>* getCorrespondingCallTreeNodes(){return &CorrespondingCallTreeNodes;}
bool isSuitedForNestingStatistics = true;
private:
PatternOccurrence* PatternOcc;
clang::SourceLocation SurLoc;
clang::SourceLocation StartSLocation;
clang::SourceLocation EndSLocation;
std::vector<PatternGraphNode*> Parents;
std::vector<PatternGraphNode*> Children;
std::vector<PatternCodeRegion*> PatternParents;
std::vector<PatternCodeRegion*> PatternChildren;
std::vector<int> LOCofCallTree;
int LinesOfCode = 0;
std::vector<CallTreeNode*> CorrespondingCallTreeNodes;
};
/**
* The pattern stack is used to keep track of the nesting of patterns and functions.
*/
extern std::vector<PatternCodeRegion*> PatternContext;
/**
*The OnlyPatternContext only keeps track of the nesting of patterns.
*/
extern std::vector<PatternCodeRegion*> OnlyPatternContext;
extern std::vector<PatternOccurrence*> OccStackForHalstead;
void AddToPatternStack(PatternCodeRegion* PatternOcc);
void AddToOnlyPatternStack(PatternCodeRegion* PatternCodeReg);
PatternCodeRegion* GetTopPatternStack();
PatternCodeRegion* GetTopOnlyPatternStack();
void RemoveFromPatternStack(std::string ID);
void RemoveFromOnlyPatternStack(std::string ID);
PatternCodeRegion* PatternIDisUsed(std::string ID);