00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "c_breeze.h"
00039
00040
00041
00042
00043
00044 forNode::forNode(exprNode * init, exprNode * cond, exprNode * next,
00045 stmtNode * body, const Coord coord)
00046 : loopNode(For, cond, body, coord),
00047 _init(init),
00048 _next(next)
00049 {}
00050
00051
00052
00053
00054
00055 void forNode::visit(Visitor * the_visitor)
00056 {
00057 the_visitor->at_for(this);
00058 }
00059
00060 void forNode::walk(Walker & the_walker)
00061 {
00062 Walker::Order ord = the_walker.order();
00063
00064 if (ord == Walker::Preorder || ord == Walker::Both)
00065 the_walker.at_for(this, Walker::Preorder);
00066
00067 if (the_walker.depth() == Walker::Subtree) {
00068
00069
00070 if (init())
00071 init()->walk(the_walker);
00072
00073 if (cond())
00074 cond()->walk(the_walker);
00075
00076 if (next())
00077 next()->walk(the_walker);
00078
00079 if (body())
00080 body()->walk(the_walker);
00081 }
00082
00083 if (ord == Walker::Postorder || ord == Walker::Both)
00084 the_walker.at_for(this, Walker::Postorder);
00085 }
00086
00087
00088
00089
00090
00091 void forNode::dataflow(FlowVal * v, FlowProblem & fp)
00092 {
00093 if (fp.forward()) {
00094 fp.flow_for(v, this, FlowProblem::Entry);
00095
00096 if (init())
00097 if (fp.basicblocks()) {
00098 fp.flow_basicblock(v, init(), FlowProblem::Entry);
00099 fp.flow_basicblock(v, init(), FlowProblem::Exit);
00100 }
00101 else
00102 init()->dataflow(v, fp);
00103
00104
00105
00106 v->meet(at_loop_head());
00107
00108 if (cond())
00109 if (fp.basicblocks()) {
00110 fp.flow_basicblock(v, cond(), FlowProblem::Entry);
00111 fp.flow_basicblock(v, cond(), FlowProblem::Exit);
00112 }
00113 else
00114 cond()->dataflow(v, fp);
00115
00116
00117
00118
00119 FlowVal * bv = v->clone();
00120
00121 if (body())
00122 body()->dataflow(bv, fp);
00123
00124
00125
00126 bv->meet(at_loop_tail());
00127
00128 if (next())
00129 if (fp.basicblocks()) {
00130 fp.flow_basicblock(v, next(), FlowProblem::Entry);
00131 fp.flow_basicblock(v, next(), FlowProblem::Exit);
00132 }
00133 else
00134 next()->dataflow(v, fp);
00135
00136
00137
00138 at_loop_head()->meet_and_diff(bv, fp);
00139 delete bv;
00140
00141
00142
00143
00144 if (! cond())
00145 v->to_top();
00146
00147
00148
00149 v->meet(at_exit());
00150
00151 fp.flow_for(v, this, FlowProblem::Exit);
00152 }
00153 else {
00154 fp.flow_for(v, this, FlowProblem::Exit);
00155
00156
00157
00158 at_exit()->meet_and_diff(v, fp);
00159
00160
00161
00162 FlowVal * bv = at_loop_head()->clone();
00163
00164 if (next())
00165 if (fp.basicblocks()) {
00166 fp.flow_basicblock(v, next(), FlowProblem::Exit);
00167 fp.flow_basicblock(v, next(), FlowProblem::Entry);
00168 }
00169 else
00170 next()->dataflow(v, fp);
00171
00172
00173
00174 at_loop_tail()->meet_and_diff(bv, fp);
00175
00176
00177
00178
00179 if (body())
00180 body()->dataflow(bv, fp);
00181
00182
00183
00184
00185 if (! cond())
00186 v->to_top();
00187
00188
00189
00190 v->meet(bv);
00191 delete bv;
00192
00193 if (cond())
00194 if (fp.basicblocks()) {
00195 fp.flow_basicblock(v, cond(), FlowProblem::Exit);
00196 fp.flow_basicblock(v, cond(), FlowProblem::Entry);
00197 }
00198 else
00199 cond()->dataflow(v, fp);
00200
00201
00202
00203 at_loop_head()->meet_and_diff(v, fp);
00204
00205 if (init())
00206 if (fp.basicblocks()) {
00207 fp.flow_basicblock(v, init(), FlowProblem::Exit);
00208 fp.flow_basicblock(v, init(), FlowProblem::Entry);
00209 }
00210 else
00211 init()->dataflow(v, fp);
00212
00213 fp.flow_for(v, this, FlowProblem::Entry);
00214 }
00215 }
00216
00217
00218
00219
00220
00221 void forNode::output_stmt(output_context & ct, Node * parent)
00222 {
00223 ct << "for " << '(';
00224
00225 if (init())
00226 init()->output(ct, this);
00227
00228 ct.space();
00229 ct << ';';
00230 ct.space();
00231
00232 if (cond())
00233 cond()->output(ct, this);
00234
00235 ct.space();
00236 ct << ';';
00237 ct.space();
00238
00239 if (next())
00240 next()->output(ct, this);
00241
00242 ct.space();
00243 ct << ')';
00244 ct.space();
00245
00246 if (body())
00247 body()->output(ct, this);
00248 else
00249 ct << ';';
00250 }
00251
00252
00253
00254
00255
00256 Node * forNode::change(Changer & the_changer, bool redispatch)
00257 {
00258 Changer::Order ord = the_changer.order();
00259 forNode * the_for = this;
00260
00261 if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00262 the_for = (forNode *) the_changer.at_for(the_for, Changer::Preorder);
00263
00264 if (the_for) {
00265
00266 if (the_for != this)
00267 return the_for->change(the_changer, true);
00268
00269 exprNode * old_init = the_for->init();
00270 if (old_init) {
00271 exprNode * new_init = (exprNode *) old_init->change(the_changer);
00272 if (old_init != new_init) {
00273
00274
00275 the_for->init(new_init);
00276 }
00277 }
00278
00279 exprNode * old_cond = the_for->cond();
00280 if (old_cond) {
00281 exprNode * new_cond = (exprNode *) old_cond->change(the_changer);
00282 if (old_cond != new_cond) {
00283
00284
00285 the_for->cond(new_cond);
00286 }
00287 }
00288
00289 exprNode * old_next = the_for->next();
00290 if (old_next) {
00291 exprNode * new_next = (exprNode *) old_next->change(the_changer);
00292 if (old_next != new_next) {
00293
00294
00295 the_for->next(new_next);
00296 }
00297 }
00298
00299 blockNode * old_body = the_for->body();
00300 if (old_body) {
00301 blockNode * new_body = (blockNode *) old_body->change(the_changer);
00302 if (old_body != new_body) {
00303
00304
00305 the_for->body(new_body);
00306 }
00307 }
00308
00309 }
00310
00311 if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00312 the_for = (forNode *) the_changer.at_for(the_for, Changer::Postorder);
00313
00314 return the_for;
00315 }
00316
00317
00318
00319
00320
00321
00322 forNode::~forNode()
00323 {
00324
00325
00326 }