ManagerSideEffectStandard.cpp

Go to the documentation of this file.
00001 
00017 #include "ManagerSideEffectStandard.hpp"
00018 #include <Utils/Util.hpp>
00019 
00020 
00021 namespace OA {
00022   namespace SideEffect {
00023 
00024 static bool debug = false;
00025 
00034 /* Deprecated, replace functionality if necessary MMS 7/6/06
00035 class RefVisitor : public virtual LocationVisitor {
00036   private:
00037     std::set<SymHandle>& mRefSymSet;
00038   public:
00039     bool mRef;
00040 
00041     RefVisitor(std::set<SymHandle> &pRefSymSet)
00042         : mRefSymSet(pRefSymSet), mRef(true) {}
00043     ~RefVisitor() {}
00044     void visitNamedLoc(NamedLoc& loc) 
00045       { 
00046         if (mRefSymSet.find(loc.getSymHandle()) != mRefSymSet.end())
00047         { mRef = true; } 
00048         else { mRef = false; }
00049       }
00050     void visitUnnamedLoc(UnnamedLoc& loc) { mRef = true; }
00051     void visitInvisibleLoc(InvisibleLoc& loc) { mRef = true; }
00052     void visitUnknownLoc(UnknownLoc& loc) { mRef = true; }
00053     void visitLocSubSet(LocSubSet& loc) { 
00054         // have this visitor visit the base location
00055         OA_ptr<Location> baseLoc = loc.getLoc();
00056         baseLoc->acceptVisitor(*this);
00057     }
00058 };
00059 */
00060 
00061 ManagerSideEffectStandard::ManagerSideEffectStandard(OA_ptr<SideEffectIRInterface> _ir) : mIR(_ir)
00062 {
00063  OA_DEBUG_CTRL_MACRO("DEBUG_ManagerSideEffectStandard:ALL", debug);
00064 }
00065 
00066 
00075 OA_ptr<SideEffectStandard> 
00076 ManagerSideEffectStandard::performAnalysis(ProcHandle proc, 
00077                                  OA_ptr<Alias::Interface> alias,
00078                                  OA_ptr<InterSideEffectInterface> inter)
00079 {
00080   mProc = proc;
00081   if (debug) {
00082       std::cout << "ManagerSideEffectStandard: proc = " << mIR->toString(proc)
00083                 << std::endl;
00084   }
00085 
00086   // create a new (waiting to be filled) SideEffectStandard as member
00087   OA_ptr<SideEffectStandard> retSideEffect;
00088   retSideEffect= new SideEffectStandard();
00089 
00090   //alias->dump(std::cout,mIR);
00091 
00092   // empty out all the sets
00093   retSideEffect->emptyLMOD();
00094   retSideEffect->emptyMOD();
00095   retSideEffect->emptyLDEF();
00096   retSideEffect->emptyDEF();
00097   retSideEffect->emptyLUSE();
00098   retSideEffect->emptyUSE();
00099   retSideEffect->emptyLREF();
00100   retSideEffect->emptyREF();
00101   
00102   // loop through statements
00103   OA_ptr<OA::IRStmtIterator> sIt = mIR->getStmtIterator(proc);
00104   for ( ; sIt->isValid(); (*sIt)++) {
00105     OA::StmtHandle stmt = sIt->current();
00106     if (debug) {
00107         std::cout << "\tstmt = ";
00108         mIR->dump(stmt,std::cout);
00109     }
00110 
00111     // for each use memory reference in the stmt
00112     OA_ptr<MemRefHandleIterator> mrIterPtr = mIR->getUseMemRefs(stmt);
00113     for (; mrIterPtr->isValid(); (*mrIterPtr)++ )
00114     {
00115       MemRefHandle memref = mrIterPtr->current();
00116       if (debug) {
00117         std::cout << "\tmemref = ";
00118         mIR->dump(memref,std::cout);
00119       }
00120 
00121       // each location the memory reference may reference
00122       OA_ptr<LocIterator> locIterPtr = alias->getMayLocs(memref);
00123       for (; locIterPtr->isValid(); ++(*locIterPtr)) {
00124 
00125         OA_ptr<Location> useLoc = locIterPtr->current();
00126         if (debug) {
00127             std::cout << "useLoc = ";
00128             useLoc->dump(std::cout, mIR);
00129         }
00130 
00131         // DEPRECATED, no longer necessary, alias analysis only maps
00132         // to locations visible within the procedure, MMS 7/6/06
00133         // will only put into these sets if the location is referenced
00134         // in the procedure
00135         //useLoc->acceptVisitor(refVisitor);
00136         //if  (refVisitor.mRef == true) {
00137 
00138         // put each location used through a memory reference in LREF and REF
00139         retSideEffect->insertLREF( useLoc);
00140         retSideEffect->insertREF( useLoc);
00141     
00142         // put each location used through a memory reference in LUSE 
00143         // and USE if the location is not already in DEF
00144         // FIXME?: assuming everything is used in a statement before 
00145         // anything
00146         // is defined, is this not the case in things like short circuits?
00147         
00148         // CONSERVATIVE FIXME: just do all USEs, to do upward exposed need
00149         // CFG, to do only USEd, need to calc DEF first
00150         //if (!retSideEffect->inDEF(useLoc)) {
00151             
00152                 retSideEffect->insertLUSE(useLoc);
00153                 retSideEffect->insertUSE(useLoc);
00154         //    }
00155         //}
00156       }
00157     }
00158 
00159     // for each def memory reference in the stmt
00160     mrIterPtr = mIR->getDefMemRefs(stmt);
00161     for (; mrIterPtr->isValid(); (*mrIterPtr)++ )
00162     {
00163       MemRefHandle memref = mrIterPtr->current();
00164       if (debug) {
00165         std::cout << "\tmemref = ";
00166         mIR->dump(memref,std::cout);
00167       }
00168       
00169       // put each location may defined into LMOD and MOD
00170       OA_ptr<LocIterator> locIterPtr = alias->getMayLocs(memref);
00171       for (; locIterPtr->isValid(); ++(*locIterPtr)) {
00172         OA_ptr<Location> mayDef = locIterPtr->current();
00173         if (debug) {
00174             std::cout << "mayDef = ";
00175             mayDef->dump(std::cout, mIR);
00176         }
00177 
00178         // AGAIN, DEPRECATED
00179         // will only put into these sets if the location is referenced
00180         // in the procedure
00181         //mayDef->acceptVisitor(refVisitor);
00182         //if  (refVisitor.mRef == true) {
00183         retSideEffect->insertLMOD(mayDef);
00184         retSideEffect->insertMOD(mayDef);
00185         //}
00186       } 
00187 
00188       // put each location must defined into LDEF and DEF
00189       locIterPtr = alias->getMustLocs(memref);
00190       for (; locIterPtr->isValid(); ++(*locIterPtr)) {
00191         OA_ptr<Location> mustDef = locIterPtr->current();
00192 
00193         // will only put into these sets if the location is referenced
00194         // in the procedure
00195         //mustDef->acceptVisitor(refVisitor);
00196         //if (refVisitor.mRef == true) {
00197         retSideEffect->insertLDEF(mustDef);
00198         retSideEffect->insertDEF(mustDef);
00199         //}
00200       } 
00201     }
00202     
00203     // Iterate over procedure calls of a statement
00204     // to determine their effect
00205     OA_ptr<IRCallsiteIterator> callsiteItPtr = mIR->getCallsites(stmt);
00206     for ( ; callsiteItPtr->isValid(); ++(*callsiteItPtr)) {
00207       CallHandle call = callsiteItPtr->current();
00208       if (debug) {
00209         std::cout << "\tcall = " << mIR->toString(call) << std::endl;
00210       }
00211 
00212       OA_ptr<LocIterator> locIterPtr;
00213       
00214       // MOD
00215       locIterPtr = inter->getMODIterator(call);
00216       for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
00217           retSideEffect->insertMOD(locIterPtr->current());
00218           if (debug) {
00219             std::cout << "\tinserting loc = ";
00220             locIterPtr->current()->dump(std::cout,mIR);
00221             std::cout << "\tinto MOD" << std::endl;
00222           }
00223       } 
00224       // DEF
00225       locIterPtr = inter->getDEFIterator(call);
00226       for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
00227           retSideEffect->insertDEF(locIterPtr->current());
00228       } 
00229       // USE
00230       locIterPtr = inter->getUSEIterator(call);
00231       for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
00232           //if (!retSideEffect->inDEF(locIterPtr->current())) {
00233           //FIXME: don't know order of use vs def in func call
00234           OA_ptr<Location> Loc = locIterPtr->current();
00235           if (debug) {
00236               std::cout << "SideEffectStandard USE retSideEffect  = ";
00237               Loc->dump(std::cout);
00238               std::cout << std::endl;
00239           }
00240           retSideEffect->insertUSE(Loc);  
00241          // retSideEffect->insertUSE(locIterPtr->current());
00242           //}
00243       } 
00244       // REF
00245       locIterPtr = inter->getREFIterator(call);
00246       for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
00247           retSideEffect->insertREF(locIterPtr->current());
00248       } 
00249     }
00250         
00251   } // end of loop over statements
00252 
00253   return retSideEffect;
00254 }
00255   } // end of namespace SideEffect
00256 } // end of namespace OA