00001 00014 #include "InvisibleLoc.hpp" 00015 #include <OpenAnalysis/Location/LocationVisitor.hpp> 00016 00017 namespace OA { 00018 00019 static bool debug = false; 00020 00021 InvisibleLoc::InvisibleLoc(InvisibleLoc &other) 00022 { 00023 OA_DEBUG_CTRL_MACRO("DEBUG_InvisibleLoc:ALL", debug); 00024 mMRE = other.mMRE; 00025 } 00026 00027 SymHandle InvisibleLoc::getBaseSym() 00028 { 00029 OA_ptr<MemRefExpr> m = mMRE; // Stupid Sun CC 5.4 00030 00031 // if our mre is another RefOp then call recursively 00032 if (mMRE->isaRefOp()) { 00033 OA_ptr<RefOp> refOp = m.convert<RefOp>(); 00034 return refOp->getBaseSym(); 00035 } 00036 // otherwise should be a named ref 00037 assert(mMRE->isaNamed()); 00038 OA_ptr<NamedRef> namedRef = m.convert<NamedRef>(); 00039 return namedRef->getSymHandle(); 00040 } 00041 00042 void InvisibleLoc::acceptVisitor(LocationVisitor& pVisitor) 00043 { 00044 pVisitor.visitInvisibleLoc(*this); 00045 } 00046 00052 /* 00053 The Invisible Location will just return same InvisibleLoc 00054 */ 00055 OA_ptr<Location> InvisibleLoc::getBaseLoc() 00056 { 00057 OA_ptr<Location> retval; 00058 retval = new InvisibleLoc(*this); 00059 return retval; 00060 } 00061 00062 /* some of this code can be used for InvisibleLoc::getBaseSym 00063 OA_ptr<Location> retval; 00064 if (mMRE->isaNamed()) { 00065 OA_ptr<MemRefExpr> m = mMRE; // Stupid Sun CC 5.4 00066 OA_ptr<NamedRef> namedRef = m.convert<NamedRef>(); 00067 retval = new NamedLoc(namedRef->getSymHandle(),false); 00068 } else if (mMRE->isaRefOp()) { 00069 OA_ptr<MemRefExpr> m = mMRE; // Stupid Sun CC 5.4 00070 OA_ptr<RefOp> refOp = m.convert<RefOp>(); 00071 retval = new NamedLoc(refOp->getBaseSym(),false); 00072 } else { 00073 assert(0); // shouldn't have an invisible loc without a named base loc 00074 } 00075 return retval; 00076 } 00077 */ 00078 00079 00088 bool InvisibleLoc::operator<(Location& other) 00089 { 00090 if(getOrder() < other.getOrder()) { return true; } 00091 else if(getOrder() > other.getOrder()) { return false; } 00092 00093 // if execution gets here then we're comparing two instances of the same 00094 // class 00095 InvisibleLoc& loc = static_cast<InvisibleLoc &>(other); 00096 00097 if (getMemRefExpr() < loc.getMemRefExpr() ) 00098 { return true; } else { return false; } 00099 } 00100 00101 bool InvisibleLoc::operator==(Location& other) 00102 { 00103 if(getOrder() != other.getOrder()) { return false; } 00104 00105 // if execution gets here then we're comparing two instances of the same 00106 // class 00107 InvisibleLoc& loc = static_cast<InvisibleLoc &>(other); 00108 00109 if ( getMemRefExpr() == loc.getMemRefExpr() ) 00110 { return true; } 00111 else { return false; } 00112 } 00113 00114 class equivalentMREsVisitor : public virtual MemRefExprVisitor { 00115 private: 00116 OA_ptr<MemRefExpr> innermost_mre; 00117 int numDerefs; 00118 public: 00119 equivalentMREsVisitor() 00120 { 00121 numDerefs=0; 00122 } 00123 ~equivalentMREsVisitor() {} 00124 void visitNamedRef(NamedRef& ref) { 00125 numDerefs=0; 00126 innermost_mre = ref.clone(); 00127 } 00128 void visitUnnamedRef(UnnamedRef& ref) { 00129 numDerefs=0; 00130 innermost_mre = ref.clone(); 00131 } 00132 void visitUnknownRef(UnknownRef& ref) { 00133 assert(0); 00134 } 00135 void visitAddressOf(AddressOf& ref) { 00136 OA_ptr<MemRefExpr> mre = ref.getMemRefExpr(); 00137 if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); } 00138 } 00139 void visitDeref(Deref& ref) { 00140 numDerefs++; 00141 OA_ptr<MemRefExpr> mre = ref.getMemRefExpr(); 00142 if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); } 00143 } 00144 virtual void visitSubSetRef(SubSetRef& ref) { 00145 OA_ptr<MemRefExpr> mre = ref.getMemRefExpr(); 00146 if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); } 00147 } 00148 int getnumDerefs() { return numDerefs; } 00149 OA_ptr<MemRefExpr> getInnermostMRE() { return innermost_mre; } 00150 }; 00151 00152 00153 class InvisibleLocMayOverlapVisitor : public virtual LocationVisitor { 00154 private: 00155 InvisibleLoc& mThisLoc; 00156 public: 00157 bool mMayOverlap; 00158 00159 InvisibleLocMayOverlapVisitor(InvisibleLoc& thisLoc) 00160 : mThisLoc(thisLoc), mMayOverlap(true) {} 00161 ~InvisibleLocMayOverlapVisitor() {} 00162 00163 // we don't overlap named locations because if we did then those 00164 // named memory references should have been mapped to same invisible 00165 // instead of being mapped to a named location 00166 void visitNamedLoc(NamedLoc& loc) { mMayOverlap = false; } 00167 00168 // we don't overlap other unnamed locations for a similar reason 00169 void visitUnnamedLoc(UnnamedLoc& loc) { mMayOverlap = false; } 00170 00171 // only overlap with other Invisibles that have an equivalent MemRefExpr 00172 // InvisibleLocs overlap if they have the same number of dereferences 00173 // and the same base symbol 00174 void visitInvisibleLoc(InvisibleLoc& loc) 00175 { 00176 00177 mMayOverlap = false; 00178 00179 equivalentMREsVisitor eVisitor1; 00180 OA_ptr<MemRefExpr> mre1 = mThisLoc.getMemRefExpr(); 00181 mre1->acceptVisitor(eVisitor1); 00182 OA_ptr<MemRefExpr> inner_mre1 = eVisitor1.getInnermostMRE(); 00183 int numderefs1 = eVisitor1.getnumDerefs(); 00184 00185 OA_ptr<MemRefExpr> mre2 = loc.getMemRefExpr(); 00186 equivalentMREsVisitor eVisitor2; 00187 mre2->acceptVisitor(eVisitor2); 00188 int numderefs2 = eVisitor2.getnumDerefs(); 00189 OA_ptr<MemRefExpr> inner_mre2 = eVisitor2.getInnermostMRE(); 00190 00191 if(numderefs1 == numderefs2) { 00192 if(inner_mre1->isaNamed() && inner_mre2->isaNamed()) { 00193 OA_ptr<NamedRef> named1 = inner_mre1.convert<NamedRef>(); 00194 OA_ptr<NamedRef> named2 = inner_mre2.convert<NamedRef>(); 00195 if(named1->getSymHandle() == named2->getSymHandle()) { 00196 mMayOverlap = true; 00197 } 00198 } 00199 } 00200 } 00201 00202 // all locs overlap with the UnknownLoc 00203 void visitUnknownLoc(UnknownLoc& loc) { mMayOverlap = true; } 00204 00205 // if the other location is a subset and we are not then 00206 // make the other location do the work 00207 void visitLocSubSet(LocSubSet& loc) 00208 { mMayOverlap = loc.mayOverlap(mThisLoc); } 00209 }; 00210 00211 bool InvisibleLoc::mayOverlap(Location& other) 00212 { 00213 // apply the visitor to the other location and return result 00214 InvisibleLocMayOverlapVisitor mayOverlapVisitor(*this); 00215 other.acceptVisitor(mayOverlapVisitor); 00216 return mayOverlapVisitor.mMayOverlap; 00217 } 00218 00219 class InvisibleLocMustOverlapVisitor : public virtual LocationVisitor { 00220 private: 00221 InvisibleLoc& mThisLoc; 00222 public: 00223 bool mMustOverlap; 00224 00225 InvisibleLocMustOverlapVisitor(InvisibleLoc& thisLoc) 00226 : mThisLoc(thisLoc), mMustOverlap(false) {} 00227 ~InvisibleLocMustOverlapVisitor() {} 00228 00229 // we don't overlap other named locations 00230 void visitNamedLoc(NamedLoc& loc) { mMustOverlap = false; } 00231 00232 void visitUnnamedLoc(UnnamedLoc& loc) { mMustOverlap = false; } 00233 00234 // if the memory reference expression is equivalent 00235 // then we must overlap with another invisible location 00236 void visitInvisibleLoc(InvisibleLoc& loc) 00237 { if ( mThisLoc.getMemRefExpr() == loc.getMemRefExpr() ) 00238 { mMustOverlap = true; } else { mMustOverlap = false; } 00239 } 00240 00241 // no locs must overlap with the UnknownLoc 00242 void visitUnknownLoc(UnknownLoc& loc) { mMustOverlap = false; } 00243 00244 // if the other location is a subset and we are not then 00245 // make the other location do the work 00246 void visitLocSubSet(LocSubSet& loc) 00247 { mMustOverlap = loc.mustOverlap(mThisLoc); } 00248 }; 00249 00250 bool InvisibleLoc::mustOverlap(Location& other) 00251 { 00252 // apply the visitor to the other location and return result 00253 InvisibleLocMustOverlapVisitor mustOverlapVisitor(*this); 00254 other.acceptVisitor(mustOverlapVisitor); 00255 return mustOverlapVisitor.mMustOverlap; 00256 } 00257 00262 bool InvisibleLoc::subSetOf(Location & other) 00263 { 00264 return mustOverlap(other); 00265 } 00266 00267 void InvisibleLoc::output(IRHandlesIRInterface& pIR) 00268 { 00269 sOutBuild->objStart("InvisibleLoc"); 00270 00271 sOutBuild->fieldStart("mMRE"); 00272 mMRE->output(pIR); 00273 sOutBuild->fieldEnd("mMRE"); 00274 00275 sOutBuild->objEnd("InvisibleLoc"); 00276 } 00277 00278 void InvisibleLoc::dump(std::ostream& os) 00279 { 00280 // string for mSymHandle 00281 os << "InvisibleLoc(this=" << this << ", mMRE="; 00282 mMRE->dump(os); 00283 os << " )" << std::endl; 00284 } 00285 00286 00287 void InvisibleLoc::dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR) 00288 { 00289 // string for mSymHandle 00290 os << "InvisibleLoc(this=" << this << ", mMRE="; 00291 mMRE->dump(os,pIR); 00292 os << " )" << std::endl; 00293 } 00294 00295 std::string InvisibleLoc::toString(OA_ptr<IRHandlesIRInterface> pIR) 00296 { 00297 std::ostringstream oss; 00298 // string for mSymHandle 00299 oss << "InvisibleLoc: "; 00300 mMRE->dump(oss,pIR); 00301 return oss.str(); 00302 } 00303 00304 } // end namespace
1.6.1