-
Notifications
You must be signed in to change notification settings - Fork 3
/
HPCPatternInstrHandler.h
74 lines (63 loc) · 2.56 KB
/
HPCPatternInstrHandler.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
#pragma once
#include "HPCParallelPattern.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
/**
* This class handles the callback that is issued when a pattern begin instrumentation call is encountered and the string argument is matched.
* It extracts all information about the pattern and patternoccurrence from the string argument and initiates creation of all involved objects.
*/
class HPCPatternBeginInstrHandler : public clang::ast_matchers::MatchFinder::MatchCallback
{
public:
void SetCurrentFnEntry(FunctionNode* FnEntry);
/**
* returns the pattern on top of the pattern stack. Is used to keept track within wich pattern we are while traversing.
*/
PatternCodeRegion* GetLastPattern() { return GetTopPatternStack(); };
/**
* @brief Analyse the match results from the pattern begin matcher to extract information about the pattern.
* After extracting design space, pattern name and pattern identifier, HPCParallelPattern and PatternOccurrence objects are looked up in the database.
* If they do not already exist, they are created.
* Then, a PatternCodeRegion object is created for this particular encounter.
*
* @param Result Match results from the pattern begin matcher.
**/
virtual void run (const clang::ast_matchers::MatchFinder::MatchResult &Result);
private:
/**
* Is used to keep track within which function we are while traversing.
*/
FunctionNode* CurrentFnEntry;
};
/**
* See HPCPatternBeginInstrHandler and HPCPatternEndInstrHandler::run()
*/
class HPCPatternEndInstrHandler : public clang::ast_matchers::MatchFinder::MatchCallback
{
public:
void SetCurrentFnEntry(FunctionNode* FnEntry);
/**
* Pattern end is closing a Pattern. Possibly a pattern within another pattern. This is used to get the outer pattern.
*/
PatternCodeRegion* GetLastPattern() { return LastPattern; };
/**
* returns the ID of the last encountered Pattern_End (which is not necessarily the LastPattern)
*/
std::string GetLastPatternID(){ return LastPatternID;};
/**
* @brief Extracts the pattern identifier string from the match results and removes the PatternCodeRegion from the pattern stack.
*
* @param Result Match results from the pattern end matcher.
**/
virtual void run (const clang::ast_matchers::MatchFinder::MatchResult &Result);
private:
/**
* @brief See PatternBeginInstrHandler::SetCurrentFnEntry().
*
* @param FnEntry Current function declaration database entry.
**/
FunctionNode* CurrentFnEntry;
PatternCodeRegion* LastPattern;
std::string LastPatternID;
PatternCodeRegion* LastOnlyPattern;
};