-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsmProfileGen.h
126 lines (108 loc) · 3.61 KB
/
AsmProfileGen.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
//===- AsmProfileGen.h --------------------------------------*- C++ -*-----===//
//
// The ArchC Project - Compiler Backend Generation
//
//===----------------------------------------------------------------------===//
//
// In this interface, we expose classes responsible for controlling the
// process of assembly profile files generation. Each of these files
// extensively tests a single machine instruction, by changing its operands,
// replicating it several times and embedding it inside a loop.
//
//===----------------------------------------------------------------------===//
#ifndef ASMPROFILEGEN_H
#define ASMPROFILEGEN_H
//==-- includes --==//
#include "InsnSelector/TransformationRules.h"
#include "InsnSelector/Semantic.h"
#include "InsnSelector/Search.h"
#include "PatternTranslator.h"
#include <string>
//==-- Class prototypes --==//
using namespace backendgen::expression;
namespace backendgen {
class AsmProfileGen {
// Target specific data used when specializing templates for a
// given architecture
std::string ArchName;
char CommentChar;
TransformationRules& RuleManager;
InstrManager& InstructionManager;
RegClassManager& RegisterClassManager;
OperandTableManager& OperandTable;
OperatorTableManager& OperatorTable;
PatternManager& PatMan;
// Working directory where macro files are created and output
// is stored.
const char * WorkingDir;
SearchResult* PrologImpl;
SearchResult* IncRegImpl;
SearchResult* EpilogImpl;
SearchResult* ExitImpl;
SearchResult* NopImpl;
std::vector<SearchResult*> InitRegsImpl;
const static unsigned NUM_INSTRUCTIONS = 1000;
const static unsigned NUM_ITERATIONS = 10000;
const static unsigned INITIAL_DEPTH = 5;
const static unsigned SEARCH_DEPTH = 25;
const static unsigned SEARCH_STEP = 3;
bool IsReserved(const Register* Reg) const;
const Register* GetLastAuxiliar() const;
const RegisterClass* GetGPRClass() const;
public:
AsmProfileGen(TransformationRules& TR, InstrManager &IR,
RegClassManager &RCM, OperandTableManager& OTM,
OperatorTableManager& OtTM, PatternManager& PM):
RuleManager(TR), InstructionManager(IR),
RegisterClassManager(RCM), OperandTable(OTM),
OperatorTable(OtTM), PatMan(PM) {
PrologImpl = 0;
IncRegImpl = 0;
EpilogImpl = 0;
ExitImpl = 0;
NopImpl = 0;
}
~AsmProfileGen() {
if (PrologImpl) {
delete PrologImpl;
PrologImpl = 0;
}
if (IncRegImpl) {
delete IncRegImpl;
IncRegImpl = 0;
}
if (EpilogImpl) {
delete EpilogImpl;
EpilogImpl = 0;
}
if (ExitImpl) {
delete ExitImpl;
ExitImpl = 0;
}
if (NopImpl) {
delete NopImpl;
NopImpl = 0;
}
for (std::vector<SearchResult*>::iterator I = InitRegsImpl.begin(),
E = InitRegsImpl.end(); I != E; ++I)
delete *I;
InitRegsImpl.clear();
}
void SetWorkingDir (const char * wdir) { WorkingDir = wdir; }
void SetCommentChar (char CommentChar) { this->CommentChar = CommentChar; }
void EmitRandomizedInstruction(InstrIterator Ins, SemanticIterator SI,
std::ostream &O);
SearchResult *FindImplementation(const Tree* Exp, std::ostream &Log);
std::list<const Register*>* GetAuxiliarList() const;
void PrintPatternImpl(SearchResult *SR, std::ostream &O);
void RandomizeRegsInitialization(std::ostream &O);
void GenerateProlog(std::ostream &O, const std::string &RegName);
void GenerateEpilog(std::ostream &O, const std::string &RegName,
unsigned Threshold);
void GenerateAssemblyTest(InstrIterator Ins, std::ostream &O);
void GenerateFiles();
void InferNop();
void Generate();
};
}
#endif