00001
00002
00003 #ifdef NO_STD_CHEADERS
00004 # include <stdlib.h>
00005 # include <string.h>
00006 # include <assert.h>
00007 #else
00008 # include <cstdlib>
00009 # include <cstring>
00010 # include <cassert>
00011 using namespace std;
00012 #endif
00013
00014 #include <iostream>
00015 using std::ostream;
00016 using std::endl;
00017 using std::cout;
00018 using std::cerr;
00019 #include <list>
00020 #include <set>
00021 #include <map>
00022
00023
00024 #include "ManagerLinearityStandard.hpp"
00025
00026
00027 namespace OA {
00028 namespace Linearity {
00029
00030 static bool debug = false;
00031
00032 ManagerLinearity::ManagerLinearity(OA_ptr<LinearityIRInterface> _ir) : mIR(_ir)
00033 {
00034 mSolver = new DataFlow::CFGDFSolver(DataFlow::CFGDFSolver::Forward,*this);
00035 }
00036
00037 OA_ptr<DataFlow::DataFlowSet> ManagerLinearity::initializeTop()
00038 {
00039 OA_ptr<LinearityMatrix> retval;
00040 retval = new LinearityMatrix;
00041 return retval;
00042 }
00043
00044 OA_ptr<DataFlow::DataFlowSet> ManagerLinearity::initializeBottom()
00045 {
00046 OA_ptr<LinearityMatrix> retval;
00047 retval = new LinearityMatrix;
00048 return retval;
00049 }
00050
00051 OA_ptr<DataFlow::DataFlowSet>
00052 ManagerLinearity::initializeNodeIN(OA_ptr<CFG::NodeInterface> n)
00053 {
00054 OA_ptr<LinearityMatrix> retval;
00055 retval = new LinearityMatrix;
00056 return retval;
00057 }
00058
00059 OA_ptr<DataFlow::DataFlowSet>
00060 ManagerLinearity::initializeNodeOUT(OA_ptr<CFG::NodeInterface> n)
00061 {
00062 OA_ptr<LinearityMatrix> retval;
00063 retval = new LinearityMatrix;
00064 return retval;
00065 }
00066
00067 OA_ptr<Linearity::LinearityMatrix> ManagerLinearity::performAnalysis(
00068 ProcHandle proc,
00069 OA_ptr<CFG::CFGInterface> cfg,
00070 OA_ptr<Alias::Interface> alias,
00071 OA_ptr<DataFlow::ParamBindings> paramBind, DataFlow::DFPImplement algorithm)
00072 {
00073 mProc = proc;
00074
00075 mLM = new LinearityMatrix;
00076
00077 mCFG = cfg;
00078
00079 mAlias = alias;
00080
00081 mParamBind = paramBind;
00082
00083 mExitNode = cfg->getExit();
00084
00085 mSolver->solve(cfg,algorithm);
00086
00087 OA_ptr<DataFlow::DataFlowSet> exitclone = mSolver->getOutSet(mExitNode);
00088 exitclone = exitclone->clone();
00089 mLM = exitclone.convert<LinearityMatrix>();
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 return mLM;
00193 }
00194
00195
00196 OA_ptr<DataFlow::DataFlowSet>
00197 ManagerLinearity::meet (OA_ptr<DataFlow::DataFlowSet> set1orig,
00198 OA_ptr<DataFlow::DataFlowSet> set2orig)
00199 {
00200
00201 OA_ptr<DataFlow::DataFlowSet> set1clone = set1orig->clone();
00202 OA_ptr<DataFlow::DataFlowSet> set2clone = set2orig->clone();
00203 OA_ptr<LinearityMatrix> set1 = set1clone.convert<LinearityMatrix>();
00204 OA_ptr<LinearityMatrix> set2 = set2clone.convert<LinearityMatrix>();
00205
00206 if (debug) {
00207 std::cout << "ManagerLinearityStandard::meet" << std::endl;
00208 std::cout << "\tset1 = ";
00209 set1->dump(std::cout,mIR);
00210 std::cout << ", set2 = ";
00211 set2->dump(std::cout,mIR);
00212 }
00213
00214 OA_ptr<LinearityMatrix> retval; retval = new LinearityMatrix;
00215 retval = set1->meet(set2, *mIR);
00216 if (debug) {
00217 std::cout << std::endl << "\tretval set = ";
00218 retval->dump(std::cout,mIR);
00219 std::cout << std::endl;
00220 }
00221
00222 return retval;
00223 }
00224
00226
00227 OA_ptr<DataFlow::DataFlowSet>
00228 ManagerLinearity::transfer(OA_ptr<DataFlow::DataFlowSet> in, OA::StmtHandle stmt)
00229 {
00230 OA_ptr<DataFlow::DataFlowSet> inclone = in->clone();
00231 OA_ptr<LinearityMatrix> inRecast = inclone.convert<LinearityMatrix>();
00232
00233 if (debug) {
00234 std::cout << "Top of Transfer==\n";
00235 inRecast->output(*mIR);
00236 }
00237
00238 OA_ptr<AssignPairIterator> espIterPtr
00239 = mIR->getAssignPairIterator(stmt);
00240
00241 if(!espIterPtr.ptrEqual(0)) {
00242
00243 for ( ; espIterPtr->isValid(); ++(*espIterPtr)) {
00244
00245 MemRefHandle mref = espIterPtr->currentTarget();
00246 ExprHandle expr = espIterPtr->currentSource();
00247
00248
00249 OA_ptr<ExprTree> eTreePtr = mIR->getExprTree(expr);
00250
00251 if (debug) {
00252 std::cout << "Expression Tree:\n";
00253 eTreePtr->output(*mIR);
00254 }
00255
00256
00257 LinearityLocsVisitor linearityVisitor(mIR,inRecast,mAlias,mParamBind);
00258 eTreePtr->acceptVisitor(linearityVisitor);
00259
00260
00261
00262
00263
00264
00265
00266 OA_ptr<LocIterator> lIterPtr = mAlias->getMayLocs(mref);
00267 for ( ; lIterPtr->isValid() ; ++(*lIterPtr)) {
00268 OA_ptr<Location> lPtr = lIterPtr->current();
00269
00270 inRecast->putDepsSet(lPtr,linearityVisitor.getDepsSet());
00271 }
00272 }
00273 }
00274
00275 if (debug) {
00276 std::cout << "Bottom of Transfer:::\n";
00277 inRecast->output(*mIR);
00278 }
00279
00280 return inRecast;
00281
00282 }
00283
00284 OA_ptr<Linearity::LinearityMatrix> ManagerLinearity::performAnalysis2(SymHandle sym)
00285 {
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 std::cout <<" TestCase2:\n";
00320 std::cout <<" \n";
00321 std::cout <<" *********\n";
00322 std::cout <<" * Entry *\n";
00323 std::cout <<" *********\n";
00324 std::cout <<" ;\n";
00325 std::cout <<" *********\n";
00326 std::cout <<" * a=0.0 *\n";
00327 std::cout <<" * f=0.0 *\n";
00328 std::cout <<" ********* \n";
00329 std::cout <<" ;<------------------\n";
00330 std::cout <<" ************* |\n";
00331 std::cout <<" * if (i<=N) * |\n";
00332 std::cout <<" ************* |\n";
00333 std::cout <<" |-----------; |\n";
00334 std::cout <<" | ********************* |\n";
00335 std::cout <<" | * a = a + x[i]*x[i] * |\n";
00336 std::cout <<" | * t = sin(a) * |\n";
00337 std::cout <<" | * f = f + t * |\n";
00338 std::cout <<" | ********************* |\n";
00339 std::cout <<" | ;------------------|\n";
00340 std::cout <<" |\n";
00341 std::cout <<" |\n";
00342 std::cout <<" | *********\n";
00343 std::cout <<" --------->* Exit *\n";
00344 std::cout <<" ********* \n";
00345
00346
00347 std::cout <<" START of TestCase2: NOTWORKING \n";
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 }
00420
00421 OA_ptr<Linearity::LinearityMatrix> ManagerLinearity::performAnalysis3(ProcHandle proc,
00422 OA_ptr<CFG::CFGInterface> cfg,
00423 OA_ptr<Alias::Interface> alias,
00424 OA_ptr<DataFlow::ParamBindings> paramBind)
00425 {
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482 std::cout <<" TestCase3:\n";
00483 std::cout <<" *********\n";
00484 std::cout <<" * Entry *\n";
00485 std::cout <<" *********\n";
00486 std::cout <<" |\n";
00487 std::cout <<" v\n";
00488 std::cout <<" ***************\n";
00489 std::cout <<" * a=0.0 *\n";
00490 std::cout <<" * b=0.0 *\n";
00491 std::cout <<" * c=0.0 *\n";
00492 std::cout <<" * d=0.0 *\n";
00493 std::cout <<" * a = a + x*x *\n";
00494 std::cout <<" *************** \n";
00495 std::cout <<" |\n";
00496 std::cout <<" v\n";
00497 std::cout <<" *************** \n";
00498 std::cout <<" * if (a > 10) * \n";
00499 std::cout <<" *************** \n";
00500 std::cout <<" ________true__________|__________false_______\n";
00501 std::cout <<" | |\n";
00502 std::cout <<" v v\n";
00503 std::cout <<" ********* ***************** \n";
00504 std::cout <<" * i = 0 * * c = c + x + 2 *\n";
00505 std::cout <<" ********* ***************** \n";
00506 std::cout <<" | |\n";
00507 std::cout <<" v<------------- |\n";
00508 std::cout <<" ************** | |\n";
00509 std::cout <<" * if (i<=10) * | |\n";
00510 std::cout <<" ************** | |\n";
00511 std::cout <<" --false------| | |\n";
00512 std::cout <<" | v | |\n";
00513 std::cout <<" | ********************* | |\n";
00514 std::cout <<" | * a = a + y[i] * | |\n";
00515 std::cout <<" | * b = b + y[i] + a * | |\n";
00516 std::cout <<" | * c = c/(sin(y[i])) * | |\n";
00517 std::cout <<" | * i = i + 1 * | |\n";
00518 std::cout <<" | ********************* | |\n";
00519 std::cout <<" | |______________| |\n";
00520 std::cout <<" | |\n";
00521 std::cout <<" |------------------------------->|<-------------------------\n";
00522 std::cout <<" v\n";
00523 std::cout <<" ********************\n";
00524 std::cout <<" * d = c + pow(x,1) *\n";
00525 std::cout <<" ********************\n";
00526 std::cout <<" |\n";
00527 std::cout <<" v\n";
00528 std::cout <<" *********\n";
00529 std::cout <<" * Exit *\n";
00530 std::cout <<" ********* \n";
00531
00532 std::cout <<"\nSTART of TestCase3: WORKING\n\n";
00533
00534
00535
00536 OA_ptr<LinearityMatrix> LM1; LM1 = new LinearityMatrix;
00537 OA_ptr<LinearityDepsSet> deps;
00538
00539
00540 OA_ptr<Location> a; a = new NamedLoc(SymHandle((irhandle_t)'a'),true);
00541 OA_ptr<Location> b; b = new NamedLoc(SymHandle((irhandle_t)'b'),true);
00542 OA_ptr<Location> c; c = new NamedLoc(SymHandle((irhandle_t)'c'),true);
00543 OA_ptr<Location> d; d = new NamedLoc(SymHandle((irhandle_t)'d'),true);
00544 OA_ptr<Location> x; x = new NamedLoc(SymHandle((irhandle_t)'x'),true);
00545 OA_ptr<Location> y; y = new NamedLoc(SymHandle((irhandle_t)'y'),true);
00546 OA_ptr<Location> i; i = new NamedLoc(SymHandle((irhandle_t)'i'),true);
00547
00548
00549 deps = new LinearityDepsSet(0.0);
00550
00551
00552 LM1->putDepsSet(a,deps);
00553
00554
00555 deps = new LinearityDepsSet(0.0);
00556
00557
00558 LM1->putDepsSet(b,deps);
00559
00560
00561 deps = new LinearityDepsSet(0.0);
00562
00563
00564 LM1->putDepsSet(c,deps);
00565
00566
00567 deps = new LinearityDepsSet(0.0);
00568
00569
00570 LM1->putDepsSet(d,deps);
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580 OA_ptr<LinearityDepsSet> depx, mult, add;
00581 deps = new LinearityDepsSet(a,LM1->getDepsSet(a));
00582 depx = new LinearityDepsSet(x,LM1->getDepsSet(x));
00583 mult = depx->multdiv(depx);
00584 add = deps->addsub(mult);
00585
00586
00587 LM1->putDepsSet(a,add);
00588
00589
00590
00591 OA_ptr<LinearityMatrix> LM2; LM2 = new LinearityMatrix;
00592 LM2 = LM1;
00593
00594
00595
00596 deps = new LinearityDepsSet(0.0);
00597
00598
00599 LM1->putDepsSet(i,deps);
00600
00601
00602
00603
00604
00605
00606 OA_ptr<LinearityDepsSet> depy;
00607 deps = new LinearityDepsSet(a,LM1->getDepsSet(a));
00608 depy = new LinearityDepsSet(y,LM1->getDepsSet(y));
00609 add = deps->addsub(depy);
00610
00611
00612 LM1->putDepsSet(a,add);
00613
00614
00615
00616
00617
00618
00619
00620 OA_ptr<LinearityDepsSet> depb, add2;
00621 depb = new LinearityDepsSet(b,LM1->getDepsSet(b));
00622 depy = new LinearityDepsSet(y,LM1->getDepsSet(y));
00623 deps = new LinearityDepsSet(a,LM1->getDepsSet(a));
00624 add = depy->addsub(deps);
00625 add2 = depb->addsub(add);
00626
00627
00628 LM1->putDepsSet(b,add2);
00629
00630
00631
00632
00633
00634
00635
00636 OA_ptr<LinearityDepsSet> depc, div, sin;
00637 depy = new LinearityDepsSet(y,LM1->getDepsSet(y));
00638 depc = new LinearityDepsSet(c,LM1->getDepsSet(c));
00639 sin = depy->func(depy);
00640 div = depc->multdiv(sin);
00641
00642
00643 LM1->putDepsSet(c,div);
00644
00645
00646 OA_ptr<LinearityDepsSet> depi;
00647 depi = new LinearityDepsSet(i,LM1->getDepsSet(i));
00648 add = depi->anyopk();
00649
00650
00651 LM1->putDepsSet(i,add);
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661 depx = new LinearityDepsSet(x,LM2->getDepsSet(x));
00662 depc = new LinearityDepsSet(c,LM2->getDepsSet(c));
00663 add = depx->anyopk();
00664 add2 = depc->addsub(add);
00665
00666
00667 LM2->putDepsSet(c,add2);
00668
00669
00670 mLM = new LinearityMatrix;
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680 OA_ptr<LinearityDepsSet> depp;
00681 depc = new LinearityDepsSet(c,mLM->getDepsSet(c));
00682 depx = new LinearityDepsSet(x,mLM->getDepsSet(x));
00683 depp = depx->power1(depx);
00684 add = depc->addsub(depp);
00685
00686
00687 mLM->putDepsSet(d,add);
00688
00689
00690
00691
00692
00693 return mLM;
00694 }
00695
00696
00697 }
00698 }
00699