AliasMap.hpp

Go to the documentation of this file.
00001 
00019 #ifndef AliasMap_H
00020 #define AliasMap_H
00021 
00022 #include <cassert>
00023 #include <iostream>
00024 #include <map>
00025 #include <set>
00026 #include <vector>
00027 #include <OpenAnalysis/Utils/OA_ptr.hpp>
00028 #include <OpenAnalysis/Alias/Interface.hpp>
00029 #include <OpenAnalysis/MemRefExpr/MemRefExpr.hpp>
00030 #include <OpenAnalysis/Location/Locations.hpp>
00031 
00032 #include <OpenAnalysis/IRInterface/IRHandles.hpp>
00033 #include <OpenAnalysis/OABase/Annotation.hpp>
00034 #include <OpenAnalysis/Utils/GenOutputTool.hpp>
00035 
00036 namespace OA {
00037   namespace Alias {
00038 
00039 typedef std::set<MemRefHandle> MemRefSet;
00040 typedef std::set<OA_ptr<MemRefExpr> > MemRefExprSet;
00041 typedef std::set<OA_ptr<Location> > LocSet;
00042 
00044 class AliasMapMemRefIter : public virtual MemRefIterator,
00045                            public IRHandleSetIterator<MemRefHandle>
00046 {
00047   public:
00048     AliasMapMemRefIter(OA_ptr<std::set<MemRefHandle> > pSet) 
00049         : IRHandleSetIterator<MemRefHandle>(pSet) {}
00050     ~AliasMapMemRefIter() {}
00051 
00052     void operator++() { IRHandleSetIterator<MemRefHandle>::operator++(); }
00053     bool isValid() const 
00054       { return IRHandleSetIterator<MemRefHandle>::isValid(); }
00055     MemRefHandle current() const 
00056       { return IRHandleSetIterator<MemRefHandle>::current(); }
00057     void reset() { IRHandleSetIterator<MemRefHandle>::current(); }
00058 };
00059 
00061 class IdIterator {
00062   public:
00063     IdIterator(std::map<int, OA_ptr<LocSet> >& aMap)
00064       {
00065         // iterate through ids and put them in a set
00066         std::map<int,OA_ptr<LocSet> >::iterator mapIter;
00067         for (mapIter=aMap.begin(); mapIter!=aMap.end(); mapIter++) {
00068             mSet.insert(mapIter->first);
00069         }
00070         reset();
00071       }
00072     ~IdIterator() {}
00073 
00074     void operator++() { if (isValid()) mIter++; }
00075     bool isValid() const  { return mIter!=mSet.end(); }
00076     int current() const  { return *mIter; }
00077     void reset() { mIter = mSet.begin(); }
00078   private:
00079     std::set<int> mSet;
00080     std::set<int>::iterator mIter;
00081 };
00082 
00085 class AliasMap : public virtual Alias::Interface,
00086                  public virtual Annotation 
00087 {
00088   public:
00089     AliasMap();
00090     AliasMap(ProcHandle p);
00091     AliasMap(AliasMap& other);
00092     ~AliasMap() {}
00093 
00094     static const int SET_ID_NONE; 
00095 
00096     //*****************************************************************
00097     // Alias::Interface 
00098     //*****************************************************************
00099     
00101     AliasResultType alias(MemRefHandle ref1, MemRefHandle ref2);
00102     
00104     OA_ptr<LocIterator> getMayLocs(MemRefHandle ref);
00105 
00108     OA_ptr<LocIterator> getMustLocs(MemRefHandle ref);
00109 
00111     OA_ptr<LocIterator> getMayLocs(MemRefExpr &ref, ProcHandle proc);
00112 
00114     OA_ptr<LocIterator> getMustLocs(MemRefExpr &ref, ProcHandle proc);
00115 
00117     OA_ptr<MemRefIterator> getMustAliases(MemRefHandle ref);
00118 
00120     OA_ptr<MemRefIterator> getMayAliases(MemRefHandle ref);
00121 
00123     OA_ptr<MemRefIterator> getMustAliases(OA_ptr<Location> loc);
00124 
00126     OA_ptr<MemRefIterator> getMayAliases(OA_ptr<Location> loc);
00127 
00130     OA_ptr<MemRefIterator> getMemRefIter();
00131 
00132     //*****************************************************************
00133     // Info methods unique to Alias::AliasMap
00134     //*****************************************************************
00135 
00139     OA_ptr<std::set<int> > getMapSetIds(MemRefHandle ref);
00140      
00145     int getMapSetId(OA_ptr<MemRefExpr> mre); 
00146     
00150     int getMapSetId(OA_ptr<OA::Location> pLoc); 
00151      
00155     int getMapSetId(LocSet pLocSet); 
00156 
00158     OA_ptr<IdIterator> getIdIterator();
00159  
00162     //OA_ptr<Location> getLocForSym(SymHandle sym);
00163 
00165     OA_ptr<LocIterator> getLocIterator(int setId); 
00166 
00167   /*
00169     bool isMust(int setId)
00170     { return mIdToSetStatusMap[setId]; }
00171   */
00172 
00174     bool isMust(int setId)
00175     { return (mIdToSetStatusMap[setId] == MUSTALIAS); }
00176 
00177     //*****************************************************************
00178     // Construction methods 
00179     //*****************************************************************
00180     
00182     //void setStartId(int s) { mStartId = s; }
00183 
00185     int getUnknownLocSetId() { return 0; }
00186 
00189     int getNextId() { return mStartId + mNumSets; }
00190 
00192     int makeEmptySet();
00193  
00197     void mapMemRefToMapSet(MemRefHandle ref, int setId);
00198 
00202     void mapMemRefToMapSet(OA_ptr<MemRefExpr> ref, int setId);
00203 
00206     void addLocation(OA_ptr<Location> loc, int setId);
00207 
00209     OA_ptr<std::map<int,OA_ptr<LocSet> > > getIdToLocSetMap();
00210 
00213     void aliasLocs(OA_ptr<Location> loc1, OA_ptr<Location> loc2);
00214 
00217     void remapMemRefs(int oldSetId, int newSetId);
00218 
00221     void mapToUnknown(int setId);
00222 
00224     void removeInvisibleLocs(int setId);
00225 
00226     void removeInvisibleLocs(int setId, OA_ptr<MemRefExpr> inv_memref);
00227 
00228     void removeBaseLoc(OA_ptr<Location> baseLoc, int setId);
00229 
00230     bool isPartial(int setId, OA_ptr<MemRefExpr> invloc);
00231 
00232     //*****************************************************************
00233     // Output
00234     //*****************************************************************
00235 
00237     void output(IRHandlesIRInterface& pIR);
00238 
00242     void dump(std::ostream& os, OA_ptr<OA::IRHandlesIRInterface> ir);
00243 
00244   private:
00245 
00246     OUTPUT
00247 
00248     // data members
00249     GENOUT ProcHandle mProcHandle; // procedure these sets are associated with
00250 
00251     // keep track of id mapping to location sets and status with a map
00252     GENOUT int mNumSets; 
00253     GENOUT int mStartId;
00254     GENOUT std::map<int,OA_ptr<LocSet> > mIdToLocSetMap; 
00255     GENOUT std::map<int,AliasResultType> mIdToSetStatusMap;
00256 
00257     // what memory references map to this alias map set
00258     GENOUT std::map<int,MemRefSet> mIdToMemRefSetMap;
00259 
00260     // what memory reference expressions map to this alias map set
00261     GENOUT std::map<int,MemRefExprSet> mIdToMRESetMap;
00262 
00263     // the location set a MemRefHandle maps to
00264     GENOUT std::map<MemRefHandle,std::set<int> > mMemRefToIdMap;  
00265 
00266     // set of memrefexpr for a memref
00267     //std::map<MemRefHandle,std::set<OA_ptr<MemRefExpr> > > 
00268     //    mMemRefToMRESetMap;
00269 
00270     // the location set a MemRefExpr maps to
00271     GENOUT std::map<OA_ptr<MemRefExpr>,int> mMREToIdMap;  
00272 
00273     // the location set a Location belongs to
00274     GENOUT std::map<OA_ptr<Location>,int> mLocToIdMap;    
00275 
00276 };
00277 
00278 
00279   } // end of Alias namespace
00280 } // end of OA namespace
00281 
00282 #endif
00283 

Generated on Sat Oct 31 05:21:20 2009 for OpenAnalysis by  doxygen 1.6.1