-
Notifications
You must be signed in to change notification settings - Fork 6
/
ir_cuda_rose_utils.cc
194 lines (150 loc) · 5.67 KB
/
ir_cuda_rose_utils.cc
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
/*****************************************************************************
Copyright (C) 2008 University of Southern California
Copyright (C) 2009 University of Utah
All Rights Reserved.
Purpose:
ROASE interface utilities. TODO remove all Sg references
Notes:
Update history:
01/2006 created by Chun Chen
*****************************************************************************/
#ifdef FRONTEND_ROSE
#include "ir_rose_utils.hh"
/**
* Returns the body of the for loop found by finding the first loop in
* code, and if level > 1 recursively calling on the body of the found
* loop and (level-1)
*/
SgNode* loop_body_at_level(SgNode* tnl, int level) {
SgNode *inner_nl = 0;
//Now strip out the tnl on the inner level of the for loop
//tree_node_list_iter tnli(tnl);
if (isSgBasicBlock(tnl)) {
SgStatementPtrList& tnli = isSgBasicBlock(tnl)->get_statements();
for (SgStatementPtrList::iterator it = tnli.begin(); it != tnli.end();
it++) {
if (isSgForStatement(*it)) {
inner_nl = loop_body_at_level(isSgForStatement(*it), level);
break;
}
}
}
return inner_nl;
}
SgNode* loop_body_at_level(SgForStatement* loop, int level) {
if (level > 1)
return loop_body_at_level(loop->get_loop_body(), level - 1);
return loop->get_loop_body();
}
void swap_node_for_node_list(SgNode* tn, SgNode* new_tnl) {
SgStatement *s = isSgStatement(tn);
SgStatement* p;
if (s != 0) {
p = isSgStatement(tn->get_parent());
if (p != 0) {
if (isSgBasicBlock(new_tnl)) {
/*SgStatementPtrList & list_ =
isSgBasicBlock(new_tnl)->get_statements();
if (isSgForStatement(p)) {
if (!isSgBasicBlock(isSgForStatement(p)->get_loop_body()))
p->replace_statement(s, isSgStatement(new_tnl));
else {
p->insert_statement(s, list_, true);
p->remove(s);
}
} else {
p->insert_statement(s, list_, true);
p->remove(s);
}
*/
if (isSgForStatement(p)) {
if (!isSgBasicBlock(isSgForStatement(p)->get_loop_body()))
p->replace_statement(s, isSgStatement(new_tnl));
else {
SgStatementPtrList& list_ =
isSgBasicBlock(new_tnl)->get_statements();
//std::vector<SgStatement*> list;
SgStatementPtrList::iterator it = list_.begin();
SgStatement* begin = *it;
begin->set_parent(p);
p->replace_statement(s, begin);
it++;
//SgStatement* stmt = first;
SgStatement* temp = begin;
for (; it != list_.end(); it++) {
(*it)->set_parent(p);
p->insert_statement(temp, *it, false);
temp = *it;
}
}
} else {
SgStatementPtrList& list_ =
isSgBasicBlock(new_tnl)->get_statements();
//std::vector<SgStatement*> list;
SgStatementPtrList::iterator it = list_.begin();
SgStatement* begin = *it;
begin->set_parent(p);
p->replace_statement(s, begin);
it++;
//SgStatement* stmt = first;
SgStatement* temp = begin;
for (; it != list_.end(); it++) {
(*it)->set_parent(p);
p->insert_statement(temp, *it, false);
temp = *it;
}
}
/* SgStatement* temp = s;
SgStatementPtrList::iterator it = list_.begin();
p->insert_statement(temp, *it, true);
temp = *it;
p->remove_statement(s);
it++;
for (; it != list_.end(); it++) {
p->insert_statement(temp, *it, false);
temp = *it;
}
// new_tnl->set_parent(p);
//new_tnl->get_statements();
SgStatementPtrList& list =
isSgBasicBlock(new_tnl)->get_statements();
//std::vector<SgStatement*> list;
SgStatementPtrList::iterator it = list.begin();
SgStatement* begin = *it;
begin->set_parent(p);
p->replace_statement(s, begin);
it++;
//SgStatement* stmt = first;
SgStatement* temp = begin;
for (; it != list.end(); it++) {
(*it)->set_parent(p);
p->insert_statement(temp, *it, false);
temp = *it;
}
*/
/* SgStatementPtrList& stmt_list = isSgBasicBlock(new_tnl)->get_statements();
SgStatement* target = s;
for(SgStatementPtrList::iterator it = stmt_list.begin() ; it != stmt_list.end(); it++)
{
isSgNode(*it)->set_parent(p);
p->insert_statement(isSgStateme, *it, false);
target = *it;
}
p->remove_statement(s);
*/
}else if(isSgIfStmt(p)) {
if(isSgIfStmt(p)->get_true_body() == s)
isSgIfStmt(p)->set_true_body(isSgStatement(new_tnl));
else if(isSgIfStmt(p)->get_false_body() == s)
isSgIfStmt(p)->set_false_body(isSgStatement(new_tnl));
new_tnl->set_parent(p);
}
else {
p->replace_statement(s, isSgStatement(new_tnl));
new_tnl->set_parent(p);
}
}
}
// return isSgNode(p);
}
#endif