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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
#ifndef IR_ROSE_HH
#define IR_ROSE_HH
#include <omega.h>
#include "ir_code.hh"
#include "ir_rose_utils.hh"
#include <AstInterface_ROSE.h>
#include "chill_error.hh"
#include "staticSingleAssignment.h"
#include "VariableRenaming.h"
#include "ssaUnfilteredCfg.h"
#include "virtualCFG.h"
#include <omega.h>
struct IR_roseScalarSymbol: public IR_ScalarSymbol {
SgVariableSymbol* vs_;
IR_roseScalarSymbol(const IR_Code *ir, SgVariableSymbol *vs) {
ir_ = ir;
vs_ = vs;
}
std::string name() const;
int size() const;
bool operator==(const IR_Symbol &that) const;
IR_Symbol *clone() const;
};
struct IR_roseArraySymbol: public IR_ArraySymbol {
SgVariableSymbol* vs_;
IR_roseArraySymbol(const IR_Code *ir, SgVariableSymbol* vs) {
ir_ = ir;
vs_ = vs;
}
std::string name() const;
int elem_size() const;
int n_dim() const;
omega::CG_outputRepr *size(int dim) const;
bool operator==(const IR_Symbol &that) const;
IR_ARRAY_LAYOUT_TYPE layout_type() const;
IR_Symbol *clone() const;
};
struct IR_roseConstantRef: public IR_ConstantRef {
union {
omega::coef_t i_;
double f_;
};
IR_roseConstantRef(const IR_Code *ir, omega::coef_t i) {
ir_ = ir;
type_ = IR_CONSTANT_INT;
i_ = i;
}
IR_roseConstantRef(const IR_Code *ir, double f) {
ir_ = ir;
type_ = IR_CONSTANT_FLOAT;
f_ = f;
}
omega::coef_t integer() const {
assert(is_integer());
return i_;
}
bool operator==(const IR_Ref &that) const;
omega::CG_outputRepr *convert();
IR_Ref *clone() const;
};
struct IR_roseScalarRef: public IR_ScalarRef {
SgAssignOp *ins_pos_;
int op_pos_; // -1 means destination operand, otherwise source operand
SgVarRefExp *vs_;
int is_write_;
IR_roseScalarRef(const IR_Code *ir, SgVarRefExp *sym) {
ir_ = ir;
ins_pos_ = isSgAssignOp(sym->get_parent());
op_pos_ = 0;
if (ins_pos_ != NULL)
if (sym == isSgVarRefExp(ins_pos_->get_lhs_operand()))
op_pos_ = -1;
vs_ = sym;
}
IR_roseScalarRef(const IR_Code *ir, SgVarRefExp *ins, int pos) {
ir_ = ir;
/* ins_pos_ = ins;
op_pos_ = pos;
SgExpression* op;
if (pos == -1)
op = ins->get_lhs_operand();
else
op = ins->get_rhs_operand();
*/
is_write_ = pos;
/* if (vs_ == NULL || pos > 0)
throw ir_error(
"Src operand not a variable or more than one src operand!!");
*/
vs_ = ins;
}
bool is_write() const;
IR_ScalarSymbol *symbol() const;
bool operator==(const IR_Ref &that) const;
omega::CG_outputRepr *convert();
IR_Ref *clone() const;
};
struct IR_roseArrayRef: public IR_ArrayRef {
SgPntrArrRefExp *ia_;
int is_write_;
IR_roseArrayRef(const IR_Code *ir, SgPntrArrRefExp *ia, int write) {
ir_ = ir;
ia_ = ia;
is_write_ = write;
}
bool is_write() const;
omega::CG_outputRepr *index(int dim) const;
IR_ArraySymbol *symbol() const;
bool operator==(const IR_Ref &that) const;
omega::CG_outputRepr *convert();
IR_Ref *clone() const;
};
struct IR_roseLoop: public IR_Loop {
SgNode *tf_;
IR_roseLoop(const IR_Code *ir, SgNode *tf) {
ir_ = ir;
tf_ = tf;
}
IR_ScalarSymbol *index() const;
omega::CG_outputRepr *lower_bound() const;
omega::CG_outputRepr *upper_bound() const;
IR_CONDITION_TYPE stop_cond() const;
IR_Block *body() const;
IR_Block *convert();
int step_size() const;
IR_Control *clone() const;
};
struct IR_roseBlock: public IR_Block {
SgNode* tnl_;
SgNode *start_, *end_;
IR_roseBlock(const IR_Code *ir, SgNode *tnl, SgNode *start, SgNode *end) {
ir_ = ir;
tnl_ = tnl;
start_ = start;
end_ = end;
}
IR_roseBlock(const IR_Code *ir, SgNode *tnl) {
ir_ = ir;
tnl_ = tnl;
start_ = tnl_->get_traversalSuccessorByIndex(0);
end_ = tnl_->get_traversalSuccessorByIndex(
(tnl_->get_numberOfTraversalSuccessors()) - 1);
}
omega::CG_outputRepr *extract() const;
omega::CG_outputRepr *original() const;
IR_Control *clone() const;
};
struct IR_roseIf: public IR_If {
SgNode *ti_;
IR_roseIf(const IR_Code *ir, SgNode *ti) {
ir_ = ir;
ti_ = ti;
}
~IR_roseIf() {
}
omega::CG_outputRepr *condition() const;
IR_Block *then_body() const;
IR_Block *else_body() const;
IR_Block *convert();
IR_Control *clone() const;
};
class IR_roseCode_Global_Init {
private:
static IR_roseCode_Global_Init *pinstance;
public:
SgProject* project;
static IR_roseCode_Global_Init *Instance(char** argv);
};
class IR_roseCode: public IR_Code {
protected:
SgSourceFile* file;
SgGlobal *root;
SgGlobal *firstScope;
SgSymbolTable* symtab_;
SgSymbolTable* symtab2_;
SgSymbolTable* symtab3_;
SgDeclarationStatementPtrList::iterator p;
SgFunctionDeclaration *func;
bool is_fortran_;
int i_;
StaticSingleAssignment *ssa_for_scalar;
ssa_unfiltered_cfg::SSA_UnfilteredCfg *main_ssa;
VariableRenaming *varRenaming_for_scalar;
public:
IR_roseCode(const char *filename, const char* proc_name);
~IR_roseCode();
IR_ScalarSymbol *CreateScalarSymbol(const IR_Symbol *sym, int memory_type =
0);
IR_ArraySymbol *CreateArraySymbol(const IR_Symbol *sym,
std::vector<omega::CG_outputRepr *> &size, int memory_type = 0);
IR_ScalarRef *CreateScalarRef(const IR_ScalarSymbol *sym);
IR_ArrayRef *CreateArrayRef(const IR_ArraySymbol *sym,
std::vector<omega::CG_outputRepr *> &index);
int ArrayIndexStartAt() {
if (is_fortran_)
return 1;
else
return 0;
}
void populateLists(SgNode* tnl_1, SgStatementPtrList* list_1,
SgStatementPtrList& output_list_1);
void populateScalars(const omega::CG_outputRepr *repr1,
std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1,
std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1,
std::set<std::string> &indices, std::vector<std::string> &index);
// std::set<std::string> &def_vars);
/*void findDefinitions(SgStatementPtrList &list_1,
std::set<VirtualCFG::CFGNode> &reaching_defs_1,
std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1,
std::set<std::string> &def_vars);
*/
/* void checkDependency(SgStatementPtrList &output_list_1,
std::vector<DependenceVector> &dvs1,
std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1,
std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1,
std::vector<std::string> &index, int i, int j);
void checkSelfDependency(SgStatementPtrList &output_list_1,
std::vector<DependenceVector> &dvs1,
std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1,
std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1,
std::vector<std::string> &index, int i, int j);
void checkWriteDependency(SgStatementPtrList &output_list_1,
std::vector<DependenceVector> &dvs1,
std::map<SgVarRefExp*, IR_ScalarRef*> &read_scalars_1,
std::map<SgVarRefExp*, IR_ScalarRef*> &write_scalars_1,
std::vector<std::string> &index, int i, int j);
*/
std::vector<IR_ArrayRef *> FindArrayRef(
const omega::CG_outputRepr *repr) const;
std::vector<IR_ScalarRef *> FindScalarRef(
const omega::CG_outputRepr *repr) const;
std::vector<IR_Control *> FindOneLevelControlStructure(
const IR_Block *block) const;
IR_Block *MergeNeighboringControlStructures(
const std::vector<IR_Control *> &controls) const;
IR_Block *GetCode() const;
void ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr);
void ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr);
IR_OPERATION_TYPE QueryExpOperation(const omega::CG_outputRepr *repr) const;
IR_CONDITION_TYPE QueryBooleanExpOperation(
const omega::CG_outputRepr *repr) const;
std::vector<omega::CG_outputRepr *> QueryExpOperand(
const omega::CG_outputRepr *repr) const;
IR_Ref *Repr2Ref(const omega::CG_outputRepr *) const;
/* std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> >
FindScalarDeps(const omega::CG_outputRepr *repr1,
const omega::CG_outputRepr *repr2, std::vector<std::string> index,
int i, int j);
*/
void finalizeRose();
friend class IR_roseArraySymbol;
friend class IR_roseArrayRef;
};
#endif
|