Go to the documentation of this file.00001
00015 #include "ManagerAliasMapXAIF.hpp"
00016 #include <Utils/Util.hpp>
00017
00018 namespace OA {
00019 namespace XAIF {
00020
00021 bool debug = false;
00022
00025 ManagerAliasMapXAIF::ManagerAliasMapXAIF(OA_ptr<XAIFIRInterface> _ir) : mIR(_ir) {
00026 OA_DEBUG_CTRL_MACRO("DEBUG_ManagerAliasMapXAIF:ALL", debug);
00027 }
00028
00031 OA_ptr<XAIF::AliasMapXAIF> ManagerAliasMapXAIF::performAnalysis(ProcHandle proc,
00032 OA_ptr<Alias::Interface> alias) {
00033 OA_ptr<AliasMapXAIF> retAliasMap; retAliasMap = new AliasMapXAIF(proc);
00034
00035 if(debug) {
00036 std::cout << "The Procedure is" << mIR->toString(proc) << std::endl;
00037 }
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 std::map<SymHandle,LocSet> symToLocSetMap;
00049
00050 std::map<ExprHandle,LocSet> exprToLocSetMap;
00051
00052
00053 for (OA_ptr<OA::IRStmtIterator> sItPtr = mIR->getStmtIterator(proc); sItPtr->isValid(); (*sItPtr)++) {
00054 OA::StmtHandle stmt = sItPtr->current();
00055 if (debug) {
00056 std::cout << "===========================" << std::endl << "stmt = ";
00057 mIR->dump(stmt,std::cout);
00058 std::cout << std::endl;
00059 }
00060
00061
00062 for (OA_ptr<MemRefHandleIterator> mrItPtr = mIR->getAllMemRefs(stmt); mrItPtr->isValid(); (*mrItPtr)++) {
00063 MemRefHandle memref = mrItPtr->current();
00064 if (debug) {
00065 std::cout << "memref = " << mIR->toString(memref) << std::endl;
00066 }
00067
00068
00069 for (OA_ptr<LocIterator> mayIterPtr = alias->getMayLocs(memref); mayIterPtr->isValid(); (*mayIterPtr)++) {
00070 OA_ptr<Location> loc = mayIterPtr->current();
00071
00072 if (loc->isaNamed()) {
00073 OA_ptr<NamedLoc> namedLoc = loc.convert<NamedLoc>();
00074 SymHandle sym = namedLoc->getSymHandle();
00075 symToLocSetMap[sym].insert(namedLoc.convert<Location>());
00076 }
00077 else if (loc->isaUnnamed()) {
00078 OA_ptr<UnnamedLoc> unnamedLoc = loc.convert<UnnamedLoc>();
00079 ExprHandle expr = unnamedLoc->getExprHandle();
00080 exprToLocSetMap[expr].insert(unnamedLoc.convert<Location>());
00081
00082 }
00083 else if (loc->isaInvisible()) {
00084 OA_ptr<InvisibleLoc> invLoc = loc.convert<InvisibleLoc>();
00085 OA_ptr<MemRefExpr> mre = invLoc->getMemRefExpr();
00086 assert(mre->isaRefOp());
00087 OA_ptr<RefOp> refOp = mre.convert<RefOp>();
00088 symToLocSetMap[refOp->getBaseSym()].insert(loc);
00089
00090 }
00091 else if (loc->isaSubSet()) {
00092
00093 OA_ptr<Location> base = loc->getBaseLoc();
00094
00095
00096 if (base->isaNamed()) {
00097 OA_ptr<NamedLoc> namedLoc = base.convert<NamedLoc>();
00098 SymHandle sym = namedLoc->getSymHandle();
00099 symToLocSetMap[sym].insert(loc);
00100
00101 }
00102 else if (base->isaUnnamed()) {
00103 OA_ptr<UnnamedLoc> unnamedLoc = base.convert<UnnamedLoc>();
00104 ExprHandle expr = unnamedLoc->getExprHandle();
00105 exprToLocSetMap[expr].insert(loc);
00106 }
00107 else if (base->isaInvisible()) {
00108 OA_ptr<InvisibleLoc> invLoc = base.convert<InvisibleLoc>();
00109 OA_ptr<MemRefExpr> mre = invLoc->getMemRefExpr();
00110 assert(mre->isaRefOp());
00111 OA_ptr<RefOp> refOp = mre.convert<RefOp>();
00112 symToLocSetMap[refOp->getBaseSym()].insert(loc);
00113 }
00114 }
00115 else if (loc->isaUnknown()) {
00116
00117 }
00118 }
00119 }
00120 }
00121
00122
00123
00124
00125 int uniqueId = 1;
00126
00127 std::map<OA_ptr<Location>,LocTuple> locToLocTuple;
00128 std::map<SymHandle,LocSet>::iterator symMapIter;
00129 if (debug) {std::cout << "===========DUMP LOCSETMAP================" << std::endl;}
00130 for (symMapIter=symToLocSetMap.begin(); symMapIter!=symToLocSetMap.end(); symMapIter++) {
00131
00132
00133
00134 int count = 0;
00135 bool partialFlag = false;
00136 LocSet::iterator locIter;
00137 LocSet locSet;
00138 locSet = symMapIter->second;
00139 for (locIter=locSet.begin(); locIter!=locSet.end(); locIter++) {
00140 OA_ptr<Location> loc = *locIter;
00141 if (debug) { std::cout << "loc = "; loc->dump(std::cout,mIR); }
00142
00143 if (loc->isaSubSet()) {
00144 if (partialFlag==false) {
00145 count += 2;
00146 }
00147 partialFlag = true;
00148 }
00149 else if(loc->isaNamed()) {
00150 count++;
00151 }
00152 else if(loc->isaUnnamed()) {
00153 count++;
00154 }
00155 else if(loc->isaUnknown()) {
00156 count++;
00157 }
00158 else if(loc->isaInvisible()) {
00159 OA_ptr<InvisibleLoc> invisibleLoc = loc.convert<InvisibleLoc>();
00160 OA_ptr<MemRefExpr> mre = invisibleLoc->getMemRefExpr();
00161 assert(mre->isaRefOp());
00162 OA_ptr<RefOp> refOp = mre.convert<RefOp>();
00163 if(refOp->isaSubSetRef()) {
00164 count += 2;
00165 }
00166 else {
00167 count++;
00168 }
00169 }
00170 }
00171 if (count == 0) { count = 1; }
00172 if (debug) { std::cout << "count = " << count << std::endl; }
00173
00174
00175 int currentSubOffset = 0;
00176 if (partialFlag==true) {
00177 currentSubOffset = 2;
00178 }
00179 if (debug) {std::cout << "------------SET locToLocTuple--------------" << std::endl;}
00180
00181 for (locIter=locSet.begin(); locIter!=locSet.end(); locIter++) {
00182 OA_ptr<Location> loc = *locIter;
00183
00184 if (loc->isaSubSet()) {
00185 OA_ptr<LocSubSet> subLoc = loc.convert<LocSubSet>();
00186 locToLocTuple[loc] = LocTuple(uniqueId,uniqueId+count-1,false);
00187 }
00188 else {
00189 locToLocTuple[loc] = LocTuple(uniqueId,uniqueId+count-1,true);
00190 }
00191 if (debug) { std::cout << "locToLocTuple["; loc->dump(std::cout,mIR); std::cout << "]=" << locToLocTuple[loc].getLocRange().getStart() << " - " << locToLocTuple[loc].getLocRange().getEnd() << std::endl; }
00192 }
00193 if (debug) {std::cout << "------------DONE locToLocTuple--------------" << std::endl;}
00194
00195 uniqueId += count;
00196 }
00197 if (debug) {std::cout << "===========DONE WITH LOCSETMAP================" << std::endl;}
00198
00199 if (debug) {std::cout << "===========DUMP exprToLocSetMap================" << std::endl;}
00200 std::map<ExprHandle,LocSet>::iterator exprMapIter;
00201 for (exprMapIter=exprToLocSetMap.begin(); exprMapIter!=exprToLocSetMap.end(); exprMapIter++ ) {
00202
00203
00204
00205 int count = 0;
00206 LocSet::iterator locIter;
00207 LocSet locSet;
00208 locSet= exprMapIter->second;
00209
00210
00211 if (debug) {std::cout << "------------SET locToLocTuple--------------" << std::endl;}
00212 for (locIter=locSet.begin(); locIter!=locSet.end(); locIter++) {
00213 OA_ptr<Location> loc = *locIter;
00214 if (loc->isaUnnamed()) {
00215 count+=2;
00216 locToLocTuple[loc] = LocTuple(uniqueId,uniqueId+count-1,false);
00217 }
00218 else {
00219 assert(0);
00220 }
00221 if (debug) { std::cout << "locToLocTuple["; loc->dump(std::cout,mIR); std::cout << "]=" << locToLocTuple[loc].getLocRange().getStart() << " - " << locToLocTuple[loc].getLocRange().getEnd() << std::endl; }
00222 }
00223 if (debug) {std::cout << "------------DONE locToLocTuple--------------" << std::endl;}
00224 uniqueId += count;
00225 }
00226 if (debug) {std::cout << "===========DONE WITH DUMP exprToLocSetMap================" << std::endl;}
00227
00228
00229
00230
00231
00232 if (debug) {std::cout << "==== MemRefHandles that alias analysis has info for" << std::endl;}
00233 for (OA_ptr<MemRefHandleIterator> mrItPtr = alias->getMemRefIter(); mrItPtr->isValid(); (*mrItPtr)++) {
00234 MemRefHandle memref = mrItPtr->current();
00235 if (debug) { std::cout << "for memref = " << mIR->toString(memref) << std::endl; }
00236
00237 int setId = Alias::AliasMap::SET_ID_NONE;
00238
00239 OA_ptr<std::set<LocTuple> > maySet;
00240 maySet = new std::set<LocTuple>;
00241 bool foundUnknown = false;
00242 for (OA_ptr<LocIterator> mayIterPtr = alias->getMayLocs(memref); mayIterPtr->isValid(); (*mayIterPtr)++) {
00243 OA_ptr<Location> loc = mayIterPtr->current();
00244 if (loc->isaUnknown()) {
00245 foundUnknown = true;
00246 }
00247 else {
00248 if (debug) { std::cout << " inserting locToLocTuple["; loc->dump(std::cout,mIR); std::cout << "]=" << locToLocTuple[loc].getLocRange().getStart() << " - " << locToLocTuple[loc].getLocRange().getEnd() << std::endl; }
00249 maySet->insert(locToLocTuple[loc]);
00250 }
00251 }
00252
00253 if (foundUnknown) {
00254 setId = 0;
00255 }
00256 else if (maySet->empty()) {
00257
00258
00259 setId = 1;
00260 }
00261 else {
00262 setId = retAliasMap->findMapSet(maySet);
00263 if (setId == Alias::AliasMap::SET_ID_NONE) {
00264 setId = getNextSetId();
00265 retAliasMap->mapLocTupleSet(maySet,setId);
00266 }
00267 }
00268 if (debug) { std::cout << " mapping memref to setId=" << setId << std::endl; }
00269 retAliasMap->mapMemRefToMapSet(memref,setId);
00270 }
00271 return retAliasMap;
00272 }
00273
00274 int ManagerAliasMapXAIF::sCurrentStartId = 2;
00275
00276 int ManagerAliasMapXAIF::getNextSetId() {
00277 return sCurrentStartId++;
00278 }
00279
00280 }
00281 }