Go to the documentation of this file.00001
00017 #include "ManagerAliasMapBasic.hpp"
00018 #include <Utils/Util.hpp>
00019
00020
00021 namespace OA {
00022 namespace Alias {
00023
00024 static bool debug = false;
00025
00033 class CreateLocationVisitor : public virtual MemRefExprVisitor {
00034 public:
00035 OA_ptr<Location> mLoc;
00036 CreateLocationVisitor(OA_ptr<AliasIRInterface> ir,
00037 ProcHandle proc) : mIR(ir),mProc(proc) {}
00038 ~CreateLocationVisitor() {}
00039 void visitNamedRef(NamedRef& ref)
00040 {
00041 mLoc = mIR->getLocation(mProc,ref.getSymHandle());
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 }
00054 void visitUnnamedRef(UnnamedRef& ref) { mLoc = new UnknownLoc; }
00055 void visitUnknownRef(UnknownRef& ref) { mLoc = new UnknownLoc; }
00056 void visitAddressOf(AddressOf& ref)
00057 {
00058 mLoc = new UnknownLoc();
00059 }
00060
00061 void visitDeref(Deref& ref) { mLoc = new UnknownLoc; }
00062
00063 void visitSubSetRef(SubSetRef& ref)
00064 {
00065
00066 ref.getMemRefExpr()->acceptVisitor(*this);
00067 if (mLoc->isaNamed()) {
00068 mLoc = new LocSubSet(mLoc,false);
00069 }
00070 }
00071
00072 private:
00073 OA_ptr<AliasIRInterface> mIR;
00074 ProcHandle mProc;
00075
00076 };
00077
00078
00081 OA_ptr<Alias::AliasMap> ManagerAliasMapBasic::performAnalysis(ProcHandle proc)
00082 {
00083 OA_DEBUG_CTRL_MACRO("DEBUG_ManagerAliasMapBasic:ALL", debug);
00084
00085 OA_ptr<AliasMap> retAliasMap;
00086 retAliasMap = new AliasMap(proc);
00087
00088 mProc = proc;
00089
00090
00091
00092
00093 unsigned int unknownSetId = 0;
00094
00095
00096 OA_ptr<OA::IRStmtIterator> sIt = mIR->getStmtIterator(proc);
00097 for ( ; sIt->isValid(); (*sIt)++) {
00098 OA::StmtHandle stmt = sIt->current();
00099
00100 if (debug) {
00101 std::cout << "\tstmt = ";
00102 mIR->dump(stmt,std::cout);
00103 }
00104
00105
00106 OA_ptr<MemRefHandleIterator> mrIterPtr = mIR->getAllMemRefs(stmt);
00107 for (; mrIterPtr->isValid(); (*mrIterPtr)++ )
00108 {
00109 MemRefHandle memref = mrIterPtr->current();
00110 if (debug) {
00111 std::cout << "\tmemref = ";
00112 mIR->dump(memref,std::cout);
00113 }
00114
00115
00116
00117
00118
00119 int setId = AliasMap::SET_ID_NONE;
00120
00121
00122 OA_ptr<MemRefExprIterator> mreIterPtr
00123 = mIR->getMemRefExprIterator(memref);
00124
00125
00126 for (; mreIterPtr->isValid(); (*mreIterPtr)++) {
00127 OA_ptr<OA::MemRefExpr> mre = mreIterPtr->current();
00128 if (debug) {
00129 std::cout << "\tmre = ";
00130 mre->dump(std::cout,mIR);
00131 }
00132
00133
00134 if(mre->isaRefOp()) {
00135 OA_ptr<RefOp> refop = mre.convert<RefOp>();
00136 if(refop->isaAddressOf()) { continue; }
00137 }
00138
00139
00140
00141
00142 if (setId == AliasMap::SET_ID_NONE) {
00143
00144 setId = retAliasMap->getMapSetId(mre);
00145 }
00146 if (debug) {
00147 std::cout << "\tsetId = " << setId << std::endl;
00148 }
00149
00150
00151 OA_ptr<Location> loc;
00152 if (setId == AliasMap::SET_ID_NONE ) {
00153
00154
00155 setId = unknownSetId;
00156
00157
00158 CreateLocationVisitor locVisitor(mIR,proc);
00159 mre->acceptVisitor(locVisitor);
00160 loc = locVisitor.mLoc;
00161
00162
00163 setId = retAliasMap->getMapSetId(loc);
00164 if (debug) {
00165 std::cout << "\tsetId = " << setId << ", loc = ";
00166 loc->dump(std::cout, mIR);
00167 }
00168 }
00169
00170
00171
00172
00173 if (setId==AliasMap::SET_ID_NONE) {
00174
00175 setId = retAliasMap->makeEmptySet();
00176
00177
00178 retAliasMap->addLocation(loc,setId);
00179 }
00180
00181
00182 if (!mre.ptrEqual(0)) { retAliasMap->mapMemRefToMapSet(mre,setId); }
00183
00184 }
00185
00186
00187 retAliasMap->mapMemRefToMapSet(memref,setId);
00188
00189 }
00190 }
00191
00192 return retAliasMap;
00193 }
00194
00195 }
00196 }