00001
00017 #include "ManagerReachConstsStandard.hpp"
00018 #include <Utils/Util.hpp>
00019
00020
00021 namespace OA {
00022 namespace ReachConsts {
00023
00024 #if defined(DEBUG_ALL) || defined(DEBUG_ManagerReachConsts)
00025 static bool debug = true;
00026 static bool extra_debug = true;
00027 static bool meet_debug = true;
00028 static bool transfer_debug = true;
00029 #else
00030 static bool debug = false;
00031 static bool extra_debug = false;
00032 static bool meet_debug = false;
00033 static bool transfer_debug = false;
00034 #endif
00035
00038 ManagerReachConstsStandard::ManagerReachConstsStandard(OA_ptr<ReachConstsIRInterface> _ir)
00039 : mIR(_ir)
00040 {
00041 OA_DEBUG_CTRL_MACRO("DEBUG_ManagerReachConstsStandard:ALL", debug);
00042 mSolver = new DataFlow::CFGDFSolver(DataFlow::CFGDFSolver::Forward,*this);
00043 }
00044
00045 void ManagerReachConstsStandard::initializeTopAndBottom()
00046 {
00047 if (debug) {
00048 std::cout << "In ManagerReachConsts::initializeTopAndBottom";
00049 std::cout << std::endl;
00050 }
00051 mAllTop = new ConstDefSet;
00052 mAllBottom = new ConstDefSet;
00053
00054
00055 OA_ptr<OA::IRStmtIterator> sIt = mIR->getStmtIterator(mProc);
00056 for ( ; sIt->isValid(); (*sIt)++) {
00057 OA::StmtHandle stmt = sIt->current();
00058
00059
00060 OA_ptr<MemRefHandleIterator> refIterPtr = mIR->getAllMemRefs(stmt);
00061 for (; refIterPtr->isValid(); (*refIterPtr)++) {
00062 MemRefHandle ref = refIterPtr->current();
00063
00064
00065 OA_ptr<LocIterator> locIterPtr = mAlias->getMustLocs(ref);
00066 for (; locIterPtr->isValid(); ++(*locIterPtr)) {
00067 OA_ptr<Location> loc = locIterPtr->current();
00068 if (debug) {
00069 std::cout << "\tMayLoc = ";
00070 loc->dump(std::cout, mIR);
00071 }
00072
00073
00074 OA_ptr<ConstValBasicInterface> nullVal; nullVal = 0;
00075 OA_ptr<ConstDef> cd; cd = new ConstDef(loc,nullVal,TOP);
00076 if (debug) {
00077 std::cout << "\tBefore insert into mAllTop" << std::endl;
00078 mAllTop->dump(std::cout, mIR);
00079 }
00080 mAllTop->insert(cd);
00081 if (debug) {
00082 std::cout << "\tAfter insert into mAllTop" << std::endl;
00083 mAllTop->dump(std::cout, mIR);
00084 }
00085 cd = new ConstDef(loc,nullVal,BOTTOM);
00086 mAllBottom->insert(cd);
00087 }
00088 }
00089
00090
00091
00092
00093
00094 }
00095 }
00096
00097 OA_ptr<DataFlow::DataFlowSet> ManagerReachConstsStandard::initializeTop()
00098 {
00099 if (mAllTop.ptrEqual(NULL)) {
00100 initializeTopAndBottom();
00101 }
00102 if (debug) {
00103 std::cout << "mAllTop = ";
00104 mAllTop->dump(std::cout,mIR);
00105 }
00106 return mAllTop;
00107 }
00108
00109 OA_ptr<DataFlow::DataFlowSet> ManagerReachConstsStandard::initializeBottom()
00110 {
00111 if (mAllBottom.ptrEqual(NULL)) {
00112 initializeTopAndBottom();
00113 }
00114 if (debug) {
00115 std::cout << "mAllBottom = ";
00116 mAllBottom->dump(std::cout,mIR);
00117 }
00118 return mAllBottom;
00119 }
00120
00126 OA_ptr<ReachConstsStandard> ManagerReachConstsStandard::performAnalysis(ProcHandle proc,
00127 OA_ptr<CFG::CFGInterface> cfg, OA_ptr<Alias::Interface> alias,
00128 OA_ptr<SideEffect::InterSideEffectInterface> interSE,
00129 DataFlow::DFPImplement algorithm)
00130 {
00131 mProc = proc;
00132
00133
00134 mRCS = new ReachConstsStandard(proc);
00135
00136
00137 mAlias = alias;
00138
00139
00140 mCFG = cfg;
00141
00142
00143 mInterSE = interSE;
00144
00145
00146
00147
00148
00149 mSolver->solve(cfg,algorithm);
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
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 return mRCS;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 OA_ptr<DataFlow::DataFlowSet>
00235 ManagerReachConstsStandard::initializeNodeIN(OA_ptr<CFG::NodeInterface> n)
00236 {
00237 if (mAllTop.ptrEqual(NULL)) {
00238 initializeTopAndBottom();
00239 }
00240 if (n.ptrEqual(mCFG->getEntry())) {
00241 return mAllBottom->clone();
00242 }
00243 OA_ptr<ConstDefSet> retval;
00244 retval = new ConstDefSet();
00245 return retval;
00246 }
00247
00248 OA_ptr<DataFlow::DataFlowSet>
00249 ManagerReachConstsStandard::initializeNodeOUT(OA_ptr<CFG::NodeInterface> n)
00250 {
00251 if (mAllTop.ptrEqual(NULL)) {
00252 initializeTopAndBottom();
00253 }
00254 if (n.ptrEqual(mCFG->getEntry())) {
00255 return mAllBottom->clone();
00256 }
00257 return mAllTop->clone();
00258 }
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00289 OA_ptr<DataFlow::DataFlowSet>
00290 ManagerReachConstsStandard::meet (OA_ptr<DataFlow::DataFlowSet> set1orig,
00291 OA_ptr<DataFlow::DataFlowSet> set2orig)
00292 {
00293
00294
00295
00296 OA_ptr<DataFlow::DataFlowSet> set1clone = set1orig->clone();
00297 OA_ptr<DataFlow::DataFlowSet> set2clone = set2orig->clone();
00298 OA_ptr<ConstDefSet> set1 = set1clone.convert<ConstDefSet>();
00299 OA_ptr<ConstDefSet> set2 = set2clone.convert<ConstDefSet>();
00300
00301 if (meet_debug) {
00302 std::cout << "MEET --------------------------------" << std::endl;
00303 std::cout << ">>>>> before pairwise refinement" << std::endl;
00304 std::cout << "set1 =" << std::endl;
00305 set1->dump(std::cout,mIR);
00306 std::cout << "set2 =" << std::endl;
00307 set2->dump(std::cout,mIR);
00308 }
00309
00310 ConstDefSetIterator set1Iter(*set1);
00311 ConstDefSetIterator set2Iter(*set2);
00312
00313 bool changeOccurred = true;
00314
00315
00316
00317 while (changeOccurred) {
00318 changeOccurred = false;
00319
00320 ConstDefSet killSet1;
00321 ConstDefSet genSet1;
00322
00323
00324
00325
00326 set1Iter.reset();
00327 for (; set1Iter.isValid(); ++(set1Iter)) {
00328 OA_ptr<ConstDef> constDef1 = set1Iter.current();
00329 OA_ptr<Location> cdLocPtr1 = constDef1->getLocPtr();
00330 OA_ptr<ConstValBasicInterface> cdConstPtr1 = constDef1->getConstPtr();
00331
00332 ConstDefSet killSet2;
00333 ConstDefSet genSet2;
00334
00335
00336 set2Iter.reset();
00337 for (; set2Iter.isValid(); ++(set2Iter)) {
00338 OA_ptr<ConstDef> constDef2 = set2Iter.current();
00339 OA_ptr<Location> cdLocPtr2 = constDef2->getLocPtr();
00340 OA_ptr<ConstValBasicInterface> cdConstPtr2 = constDef2->getConstPtr();
00341
00342 if (meet_debug) {
00343 std::cout << "in meet: pair " << constDef1->toString(mIR)
00344 << " vs. " << constDef2->toString(mIR) << std::endl;
00345 }
00346
00347 ManagerReachConstsStandard::MeetOp op = NOTHING;
00348
00349 if (cdLocPtr1->mustOverlap(*cdLocPtr2)) {
00350 if (meet_debug) {std::cout << "\tmustOp=";}
00351 op = getMustMeetOp(constDef1, constDef2);
00352 } else if (cdLocPtr1->mayOverlap(*cdLocPtr2)) {
00353 if (meet_debug) {std::cout << "\tmayOp=";}
00354 op = getMayOnlyMeetOp(constDef1, constDef2);
00355 }
00356
00357 OA_ptr<ConstDef> cd;
00358 OA_ptr<ConstValBasicInterface> nullVal;
00359 switch (op) {
00360 case CD1toBOTTOM:
00361 if (meet_debug) {std::cout << "CD1toBOTTOM" << std::endl;}
00362 killSet1.insert(constDef1);
00363 cd = new ConstDef(cdLocPtr1,nullVal,BOTTOM);
00364 genSet1.insert(cd);
00365 changeOccurred = true;
00366 break;
00367 case CD2toBOTTOM:
00368 if (meet_debug) {std::cout << "CD2toBOTTOM" << std::endl;}
00369 killSet2.insert(constDef2);
00370 cd = new ConstDef(cdLocPtr2,nullVal,BOTTOM);
00371 genSet2.insert(cd);
00372 changeOccurred = true;
00373 break;
00374 case BOTHtoBOTTOM:
00375 if (meet_debug) {std::cout << "BOTHtoBOTTOM" << std::endl;}
00376 killSet1.insert(constDef1);
00377 cd = new ConstDef(cdLocPtr1,nullVal,BOTTOM);
00378 genSet1.insert(cd);
00379 killSet2.insert(constDef2);
00380 cd = new ConstDef(cdLocPtr2,nullVal,BOTTOM);
00381 genSet2.insert(cd);
00382 changeOccurred = true;
00383 break;
00384 case CD1toVALUECD2:
00385 if (meet_debug) {std::cout << "CD1toVALUECD2" << std::endl;}
00386 killSet1.insert(constDef1);
00387 cd = new ConstDef(cdLocPtr1,cdConstPtr2,VALUE);
00388 genSet1.insert(cd);
00389 changeOccurred = true;
00390 break;
00391 case CD2toVALUECD1:
00392 if (meet_debug) {std::cout << "CD2toVALUECD1" << std::endl;}
00393 killSet2.insert(constDef2);
00394 cd = new ConstDef(cdLocPtr2,cdConstPtr1,VALUE);
00395 genSet2.insert(cd);
00396 changeOccurred = true;
00397 break;
00398 case NOTHING:
00399 if (meet_debug) {std::cout << "NOTHING" << std::endl;}
00400 break;
00401 }
00402
00403 }
00404
00405
00406
00407 ConstDefSetIterator setIter(killSet2);
00408 for (; setIter.isValid(); ++(setIter)) {
00409 OA_ptr<ConstDef> constDef = setIter.current();
00410 if (meet_debug) {
00411 int k = set2->removeANDtell(constDef);
00412 std::cout << "MEET: killed "<<k<<" from set2: (cd "
00413 << constDef->toString(mIR)
00414 << ")" << std::endl;
00415 } else {
00416 set2->remove(constDef);
00417 }
00418 }
00419
00420 ConstDefSetIterator vsetIter(genSet2);
00421 for (; vsetIter.isValid(); ++(vsetIter)) {
00422 OA_ptr<ConstDef> constDef = vsetIter.current();
00423 set2->replace(constDef->getLocPtr(),constDef->getConstPtr(),
00424 constDef->getConstDefType());
00425 if (meet_debug) {
00426 std::cout << "MEET: Replacement in set2: (cd "
00427 << constDef->toString(mIR)
00428 << ")" << std::endl;
00429 }
00430 }
00431 }
00432
00433
00434
00435 ConstDefSetIterator setIter(killSet1);
00436 for (; setIter.isValid(); ++(setIter)) {
00437 OA_ptr<ConstDef> constDef = setIter.current();
00438 if (meet_debug) {
00439 int k = set1->removeANDtell(constDef);
00440 std::cout << "MEET: killed "<<k<<" from set1: (cd "
00441 << constDef->toString(mIR) << ")" << std::endl;
00442 } else {
00443 set1->remove(constDef);
00444 }
00445 }
00446
00447 ConstDefSetIterator vsetIter(genSet1);
00448 for (; vsetIter.isValid(); ++(vsetIter)) {
00449 OA_ptr<ConstDef> constDef = vsetIter.current();
00450 set1->replace(constDef->getLocPtr(),constDef->getConstPtr(),
00451 constDef->getConstDefType());
00452 if (meet_debug) {
00453 std::cout << "MEET: Val replacement in set1: (cd "
00454 << constDef->toString(mIR) << ")" << std::endl;
00455 }
00456 }
00457 }
00458
00459
00460 if (meet_debug) {
00461 std::cout << ">>>>> after pairwise refinement, set1 and set2 should be equiv" << std::endl;
00462 std::cout << "set1 =" << std::endl;
00463 set1->dump(std::cout,mIR);
00464 std::cout << "set2 =" << std::endl;
00465 set2->dump(std::cout,mIR);
00466 }
00467
00468
00469
00470
00471 return set1;
00472
00473 }
00474
00496
00497
00498
00499
00500
00501
00502
00503
00504 OA_ptr<DataFlow::DataFlowSet>
00505 ManagerReachConstsStandard::transfer(OA_ptr<DataFlow::DataFlowSet> in, OA::StmtHandle stmt)
00506 {
00507 ConstDefSet killSet;
00508 ConstDefSet replaceSet;
00509 ConstDefSet genSet;
00510 OA_ptr<DataFlow::DataFlowSet> inclone = in->clone();
00511 OA_ptr<ConstDefSet> inRecast = inclone.convert<ConstDefSet>();
00512
00513 inclone = in->clone();
00514 OA_ptr<ConstDefSet> inRecastCopy = inclone.convert<ConstDefSet>();
00515
00516
00517
00518
00519
00520 ConstDefSetIterator cdIter(*inRecast);
00521 for (; cdIter.isValid(); ++(cdIter)) {
00522 OA_ptr<ConstDef> constDef = cdIter.current();
00523 mRCS->insertConstDef(stmt,constDef);
00524 }
00525
00526
00527 if (transfer_debug) {
00528 std::cout << "--- --- --- --- --- Top of Transfer " << std::endl;
00529
00530
00531 }
00532
00533
00534 setUseMemRef2Const(stmt, *inRecast);
00535
00536 if (debug) {
00537 std::cout << "------------------------------------------------"
00538 << std::endl;
00539 std::cout << "transfer: stmt = (" << stmt.hval() << ": "
00540 << mIR->toString(stmt) << ") :" << std::endl;
00541 std::cout << "\tConstDefsIn: ";
00542 inRecast->dump(std::cout,mIR);
00543 std::cout.flush();
00544 }
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555 {
00556
00557
00558 OA_ptr<MemRefHandleIterator> defIterPtr = mIR->getDefMemRefs(stmt);
00559 for (; defIterPtr->isValid(); (*defIterPtr)++) {
00560 MemRefHandle memref = defIterPtr->current();
00561
00562
00563 OA_ptr<LocIterator> locIterPtr = mAlias->getMayLocs(memref);
00564 for (; locIterPtr->isValid(); ++(*locIterPtr)) {
00565 OA_ptr<Location> mayLocPtr = locIterPtr->current();
00566
00567
00568 OA_ptr<ConstDefSetIterator> inIter;
00569 inIter = new ConstDefSetIterator(*inRecastCopy);
00570 for (; inIter->isValid(); ++(*inIter)) {
00571 OA_ptr<ConstDef> constDef = inIter->current();
00572 OA_ptr<Location> cdLocPtr = constDef->getLocPtr();
00573
00574
00575
00576 if (cdLocPtr->mayOverlap(*mayLocPtr)) {
00577 OA_ptr<ConstValBasicInterface> nullVal; nullVal = 0;
00578 inRecast->replace(cdLocPtr,nullVal,BOTTOM);
00579 }
00580 }
00581 }
00582 }
00583
00584
00585 OA_ptr<IRCallsiteIterator> callsiteItPtr = mIR->getCallsites(stmt);
00586 for ( ; callsiteItPtr->isValid(); ++(*callsiteItPtr)) {
00587 CallHandle expr = callsiteItPtr->current();
00588
00589 OA_ptr<LocIterator> locIterPtr;
00590
00591 locIterPtr = mInterSE->getMODIterator(expr);
00592 for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
00593 OA_ptr<Location> modLocPtr = locIterPtr->current();
00594
00595
00596 OA_ptr<ConstDefSetIterator> inIter;
00597 inIter = new ConstDefSetIterator(*inRecastCopy);
00598 for (; inIter->isValid(); ++(*inIter)) {
00599 OA_ptr<ConstDef> constDef = inIter->current();
00600 OA_ptr<Location> cdLocPtr = constDef->getLocPtr();
00601
00602
00603
00604 if (cdLocPtr->mayOverlap(*modLocPtr)) {
00605 OA_ptr<ConstValBasicInterface> nullVal; nullVal = 0;
00606 inRecast->replace(cdLocPtr,nullVal,BOTTOM);
00607 }
00608 }
00609 }
00610
00611 }
00612
00613 }
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626 OA_ptr<AssignPairIterator> espIterPtr
00627 = mIR->getAssignPairIterator(stmt);
00628 for ( ; espIterPtr->isValid(); (*espIterPtr)++) {
00629
00630 MemRefHandle mref = espIterPtr->currentTarget();
00631 ExprHandle expr = espIterPtr->currentSource();
00632
00633
00634 OA_ptr<ConstValBasicInterface> cvbiPtr; cvbiPtr = 0;
00635 OA_ptr<ExprTree> eTreePtr = mIR->getExprTree(expr);
00636
00637
00638 EvalToConstVisitor evalVisitor(mIR,mRCS);
00639 eTreePtr->acceptVisitor(evalVisitor);
00640 cvbiPtr = evalVisitor.getConstVal();
00641
00642 if (!cvbiPtr.ptrEqual(NULL)) {
00643 if (transfer_debug) {
00644 std::cout << "After eval, cvbiPtr = (" << cvbiPtr <<")"<<std::endl;
00645 std::cout.flush();
00646 std::cout << " *cvbiPTr = (" << cvbiPtr->toString()
00647 << ")" << std::endl;
00648 std::cout.flush();
00649 }
00650
00651
00652
00653 OA_ptr<LocIterator> lIterPtr = mAlias->getMustLocs(mref);
00654 for ( ; lIterPtr->isValid() ; ++(*lIterPtr)) {
00655 OA_ptr<Location> lPtr = lIterPtr->current();
00656 inRecast->replace(lPtr,cvbiPtr,VALUE);
00657 }
00658 }
00659 }
00660
00661
00662
00663 setDefMemRef2Const(stmt, *inRecast);
00664
00665 if (debug) {
00666 std::cout << "\tConstDefsOut: ";
00667 inRecast->dump(std::cout,mIR);
00668 }
00669
00670 return inRecast;
00671 }
00672
00674 ManagerReachConstsStandard::MeetOp
00675 ManagerReachConstsStandard::getMustMeetOp(OA_ptr<ConstDef> cd1, OA_ptr<ConstDef> cd2)
00676 {
00677 ConstDefType cdType1 = cd1->getConstDefType();
00678 OA_ptr<ConstValBasicInterface> cdConstPtr1 = cd1->getConstPtr();
00679 ConstDefType cdType2 = cd2->getConstDefType();
00680 OA_ptr<ConstValBasicInterface> cdConstPtr2 = cd2->getConstPtr();
00681 ManagerReachConstsStandard::MeetOp retval = NOTHING;
00682
00683
00684 switch (cdType1) {
00685 case TOP:
00686 switch (cdType2) {
00687 case TOP:
00688
00689 retval = NOTHING; break;
00690 case VALUE:
00691
00692 retval = CD1toVALUECD2; break;
00693 case BOTTOM:
00694
00695 retval = CD1toBOTTOM; break;
00696 }
00697 break;
00698
00699 case VALUE:
00700 switch (cdType2) {
00701 case TOP:
00702
00703 retval = CD2toVALUECD1; break;
00704 case VALUE:
00705
00706 if (cdConstPtr1 != cdConstPtr2) {
00707 retval = BOTHtoBOTTOM;
00708 } else {
00709 retval = NOTHING;
00710 }
00711 break;
00712 case BOTTOM:
00713
00714 retval = CD1toBOTTOM; break;
00715 }
00716 break;
00717
00718 case BOTTOM:
00719 switch (cdType2) {
00720 case TOP:
00721
00722 retval = CD2toBOTTOM; break;
00723 case VALUE:
00724
00725 retval = CD2toBOTTOM; break;
00726 case BOTTOM:
00727
00728 retval = NOTHING; break;
00729 }
00730 break;
00731 }
00732
00733 return retval;
00734 }
00735
00737 ManagerReachConstsStandard::MeetOp
00738 ManagerReachConstsStandard::getMayOnlyMeetOp(OA_ptr<ConstDef> cd1, OA_ptr<ConstDef> cd2)
00739 {
00740 ConstDefType cdType1 = cd1->getConstDefType();
00741 ConstDefType cdType2 = cd2->getConstDefType();
00742 ManagerReachConstsStandard::MeetOp retval = NOTHING;
00743
00744
00745 switch (cdType1) {
00746 case TOP:
00747 switch (cdType2) {
00748 case TOP:
00749
00750 retval = NOTHING; break;
00751 case VALUE:
00752
00753 retval = BOTHtoBOTTOM; break;
00754 case BOTTOM:
00755
00756 retval = CD1toBOTTOM; break;
00757 }
00758 break;
00759
00760 case VALUE:
00761 switch (cdType2) {
00762 case TOP:
00763
00764 retval = BOTHtoBOTTOM; break;
00765 case VALUE:
00766
00767 retval = BOTHtoBOTTOM; break;
00768 case BOTTOM:
00769
00770 retval = CD1toBOTTOM; break;
00771 }
00772 break;
00773
00774 case BOTTOM:
00775 switch (cdType2) {
00776 case TOP:
00777
00778 retval = CD2toBOTTOM; break;
00779 case VALUE:
00780
00781 retval = CD2toBOTTOM; break;
00782 case BOTTOM:
00783
00784 retval = NOTHING; break;
00785 }
00786 break;
00787 }
00788
00789 return retval;
00790 }
00791
00794 void
00795 ManagerReachConstsStandard::setUseMemRef2Const(StmtHandle stmt, const ConstDefSet& in) {
00796
00797
00798 OA_ptr<MemRefHandleIterator> useIterPtr = mIR->getUseMemRefs(stmt);
00799 for (; useIterPtr->isValid(); (*useIterPtr)++) {
00800 MemRefHandle ref = useIterPtr->current();
00801
00802
00803 OA_ptr<LocIterator> locIterPtr = mAlias->getMayLocs(ref);
00804
00805
00806 OA_ptr<Location> loc = locIterPtr->current();
00807 if (transfer_debug) {
00808 std::cout << "Finding location (" << loc->toString(mIR) << ")"
00809 << std::endl;
00810 std::cout.flush();
00811 }
00812
00813 OA_ptr<ConstDef> cdPtr = in.find(loc);
00814
00815
00816 bool allValuesAgree = true;
00817 if (cdPtr.ptrEqual(NULL)) {
00818 allValuesAgree = false;
00819 if (transfer_debug) {
00820 std::cout << "a useMemRef (" << mIR->toString(ref) << ") "
00821 << "missing ConstDef for first mayLoc ( "
00822 << loc->toString(mIR) << ")" << std::endl;
00823 std::cout.flush();
00824 }
00825 } else if (cdPtr->getConstDefType() != VALUE) {
00826 allValuesAgree = false;
00827
00828 }
00829
00830
00831 for (; (allValuesAgree) && (locIterPtr->isValid()); ++(*locIterPtr)) {
00832 OA_ptr<Location> loc = locIterPtr->current();
00833 OA_ptr<ConstDef> cdNextPtr = in.find(loc);
00834 if (cdPtr.ptrEqual(NULL)) {
00835 allValuesAgree = false;
00836 } else if (!((*cdPtr).equiv(*cdNextPtr))) {
00837 allValuesAgree = false;
00838 }
00839 }
00840 if (allValuesAgree) {
00841
00842 mRCS->updateReachConst(ref,cdPtr->getConstPtr());
00843 } else {
00844
00845 OA_ptr<ConstValBasicInterface> nullVal; nullVal = 0;
00846 mRCS->updateReachConst(ref,nullVal);
00847 }
00848 }
00849
00850 if (transfer_debug) {
00851 OA_ptr<MemRefHandleIterator> useIterPtr = mIR->getUseMemRefs(stmt);
00852 for (; useIterPtr->isValid(); (*useIterPtr)++) {
00853 MemRefHandle ref = useIterPtr->current();
00854 OA_ptr<ConstValBasicInterface> cvbiPtr = mRCS->getReachConst(ref);
00855 std::cout << "useMemRef(" << mIR->toString(ref) ;
00856 if (cvbiPtr.ptrEqual(NULL)) {
00857 std::cout << ") has no constant value." << std::endl;
00858 } else {
00859 std::cout << ") maps to VALUE="
00860 << cvbiPtr->toString() << std::endl;
00861 }
00862 }
00863 }
00864 }
00865
00868 void
00869 ManagerReachConstsStandard::setDefMemRef2Const(StmtHandle stmt, const ConstDefSet& in) {
00870
00871
00872 OA_ptr<MemRefHandleIterator> defIterPtr = mIR->getDefMemRefs(stmt);
00873 for (; defIterPtr->isValid(); (*defIterPtr)++) {
00874 MemRefHandle ref = defIterPtr->current();
00875
00876
00877 OA_ptr<LocIterator> locIterPtr = mAlias->getMayLocs(ref);
00878
00879
00880 OA_ptr<Location> loc = locIterPtr->current();
00881 if (transfer_debug) {
00882 std::cout << "Finding def location (" << loc->toString(mIR) << ")"
00883 << std::endl;
00884 std::cout.flush();
00885 }
00886
00887 OA_ptr<ConstDef> cdPtr = in.find(loc);
00888
00889
00890 bool allValuesAgree = true;
00891 if (cdPtr.ptrEqual(NULL)) {
00892 allValuesAgree = false;
00893 if (transfer_debug) {
00894 std::cout << "a defMemRef (" << mIR->toString(ref) << ") "
00895 << "missing ConstDef for first mayLoc ( "
00896 << loc->toString(mIR) << ")" << std::endl;
00897 std::cout.flush();
00898 }
00899 } else if (cdPtr->getConstDefType() != VALUE) {
00900 allValuesAgree = false;
00901
00902 }
00903
00904
00905 for (; (allValuesAgree) && (locIterPtr->isValid()); ++(*locIterPtr)) {
00906 OA_ptr<Location> loc = locIterPtr->current();
00907 OA_ptr<ConstDef> cdNextPtr = in.find(loc);
00908 if (cdPtr.ptrEqual(NULL)) {
00909 allValuesAgree = false;
00910 } else if (!((*cdPtr).equiv(*cdNextPtr))) {
00911 allValuesAgree = false;
00912 }
00913 }
00914 if (allValuesAgree) {
00915
00916 mRCS->updateReachConst(ref,cdPtr->getConstPtr());
00917 } else {
00918
00919 OA_ptr<ConstValBasicInterface> nullValue; nullValue = NULL;
00920 mRCS->updateReachConst(ref,nullValue);
00921 }
00922 }
00923
00924 if (transfer_debug) {
00925 OA_ptr<MemRefHandleIterator> defIterPtr = mIR->getDefMemRefs(stmt);
00926 for (; defIterPtr->isValid(); (*defIterPtr)++) {
00927 MemRefHandle ref = defIterPtr->current();
00928 OA_ptr<ConstValBasicInterface> cvbiPtr = mRCS->getReachConst(ref);
00929 std::cout << "defMemRef(" << mIR->toString(ref);
00930 if (cvbiPtr.ptrEqual(NULL)) {
00931 std::cout << ") has no constant value." << std::cout;
00932 } else {
00933 std::cout << ") maps to VALUE="
00934 << (mRCS->getReachConst(ref))->toString() << std::endl;
00935 }
00936 }
00937 }
00938 }
00939
00940 }
00941 }