OpenADFortTk (including Open64 and OpenAnalysis references)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
InvisibleLoc.cpp
Go to the documentation of this file.
1 
14 #include "InvisibleLoc.hpp"
16 
17 namespace OA {
18 
19 static bool debug = false;
20 
22 {
23  OA_DEBUG_CTRL_MACRO("DEBUG_InvisibleLoc:ALL", debug);
24  mMRE = other.mMRE;
25 }
26 
28 {
29  OA_ptr<MemRefExpr> m = mMRE; // Stupid Sun CC 5.4
30 
31  // if our mre is another RefOp then call recursively
32  if (mMRE->isaRefOp()) {
33  OA_ptr<RefOp> refOp = m.convert<RefOp>();
34  return refOp->getBaseSym();
35  }
36  // otherwise should be a named ref
37  assert(mMRE->isaNamed());
38  OA_ptr<NamedRef> namedRef = m.convert<NamedRef>();
39  return namedRef->getSymHandle();
40 }
41 
43 {
44  pVisitor.visitInvisibleLoc(*this);
45 }
46 
52 /*
53  The Invisible Location will just return same InvisibleLoc
54  */
56 {
57  OA_ptr<Location> retval;
58  retval = new InvisibleLoc(*this);
59  return retval;
60 }
61 
62 /* some of this code can be used for InvisibleLoc::getBaseSym
63  OA_ptr<Location> retval;
64  if (mMRE->isaNamed()) {
65  OA_ptr<MemRefExpr> m = mMRE; // Stupid Sun CC 5.4
66  OA_ptr<NamedRef> namedRef = m.convert<NamedRef>();
67  retval = new NamedLoc(namedRef->getSymHandle(),false);
68  } else if (mMRE->isaRefOp()) {
69  OA_ptr<MemRefExpr> m = mMRE; // Stupid Sun CC 5.4
70  OA_ptr<RefOp> refOp = m.convert<RefOp>();
71  retval = new NamedLoc(refOp->getBaseSym(),false);
72  } else {
73  assert(0); // shouldn't have an invisible loc without a named base loc
74  }
75  return retval;
76 }
77 */
78 
79 
89 {
90  if(getOrder() < other.getOrder()) { return true; }
91  else if(getOrder() > other.getOrder()) { return false; }
92 
93  // if execution gets here then we're comparing two instances of the same
94  // class
95  InvisibleLoc& loc = static_cast<InvisibleLoc &>(other);
96 
97  if (getMemRefExpr() < loc.getMemRefExpr() )
98  { return true; } else { return false; }
99 }
100 
102 {
103  if(getOrder() != other.getOrder()) { return false; }
104 
105  // if execution gets here then we're comparing two instances of the same
106  // class
107  InvisibleLoc& loc = static_cast<InvisibleLoc &>(other);
108 
109  if ( getMemRefExpr() == loc.getMemRefExpr() )
110  { return true; }
111  else { return false; }
112 }
113 
114 class equivalentMREsVisitor : public virtual MemRefExprVisitor {
115  private:
118  public:
120  {
121  numDerefs=0;
122  }
124  void visitNamedRef(NamedRef& ref) {
125  numDerefs=0;
126  innermost_mre = ref.clone();
127  }
129  numDerefs=0;
130  innermost_mre = ref.clone();
131  }
133  assert(0);
134  }
136  OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
137  if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
138  }
139  void visitDeref(Deref& ref) {
140  numDerefs++;
141  OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
142  if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
143  }
144  virtual void visitSubSetRef(SubSetRef& ref) {
145  OA_ptr<MemRefExpr> mre = ref.getMemRefExpr();
146  if (!mre.ptrEqual(0)) { mre->acceptVisitor(*this); }
147  }
148  int getnumDerefs() { return numDerefs; }
150 };
151 
152 
154  private:
156  public:
158 
160  : mThisLoc(thisLoc), mMayOverlap(true) {}
162 
163  // we don't overlap named locations because if we did then those
164  // named memory references should have been mapped to same invisible
165  // instead of being mapped to a named location
166  void visitNamedLoc(NamedLoc& loc) { mMayOverlap = false; }
167 
168  // we don't overlap other unnamed locations for a similar reason
169  void visitUnnamedLoc(UnnamedLoc& loc) { mMayOverlap = false; }
170 
171  // only overlap with other Invisibles that have an equivalent MemRefExpr
172  // InvisibleLocs overlap if they have the same number of dereferences
173  // and the same base symbol
175  {
176 
177  mMayOverlap = false;
178 
179  equivalentMREsVisitor eVisitor1;
181  mre1->acceptVisitor(eVisitor1);
182  OA_ptr<MemRefExpr> inner_mre1 = eVisitor1.getInnermostMRE();
183  int numderefs1 = eVisitor1.getnumDerefs();
184 
185  OA_ptr<MemRefExpr> mre2 = loc.getMemRefExpr();
186  equivalentMREsVisitor eVisitor2;
187  mre2->acceptVisitor(eVisitor2);
188  int numderefs2 = eVisitor2.getnumDerefs();
189  OA_ptr<MemRefExpr> inner_mre2 = eVisitor2.getInnermostMRE();
190 
191  if(numderefs1 == numderefs2) {
192  if(inner_mre1->isaNamed() && inner_mre2->isaNamed()) {
193  OA_ptr<NamedRef> named1 = inner_mre1.convert<NamedRef>();
194  OA_ptr<NamedRef> named2 = inner_mre2.convert<NamedRef>();
195  if(named1->getSymHandle() == named2->getSymHandle()) {
196  mMayOverlap = true;
197  }
198  }
199  }
200  }
201 
202  // all locs overlap with the UnknownLoc
203  void visitUnknownLoc(UnknownLoc& loc) { mMayOverlap = true; }
204 
205  // if the other location is a subset and we are not then
206  // make the other location do the work
208  { mMayOverlap = loc.mayOverlap(mThisLoc); }
209 };
210 
212 {
213  // apply the visitor to the other location and return result
214  InvisibleLocMayOverlapVisitor mayOverlapVisitor(*this);
215  other.acceptVisitor(mayOverlapVisitor);
216  return mayOverlapVisitor.mMayOverlap;
217 }
218 
220  private:
222  public:
224 
226  : mThisLoc(thisLoc), mMustOverlap(false) {}
228 
229  // we don't overlap other named locations
230  void visitNamedLoc(NamedLoc& loc) { mMustOverlap = false; }
231 
232  void visitUnnamedLoc(UnnamedLoc& loc) { mMustOverlap = false; }
233 
234  // if the memory reference expression is equivalent
235  // then we must overlap with another invisible location
237  { if ( mThisLoc.getMemRefExpr() == loc.getMemRefExpr() )
238  { mMustOverlap = true; } else { mMustOverlap = false; }
239  }
240 
241  // no locs must overlap with the UnknownLoc
242  void visitUnknownLoc(UnknownLoc& loc) { mMustOverlap = false; }
243 
244  // if the other location is a subset and we are not then
245  // make the other location do the work
247  { mMustOverlap = loc.mustOverlap(mThisLoc); }
248 };
249 
251 {
252  // apply the visitor to the other location and return result
253  InvisibleLocMustOverlapVisitor mustOverlapVisitor(*this);
254  other.acceptVisitor(mustOverlapVisitor);
255  return mustOverlapVisitor.mMustOverlap;
256 }
257 
263 {
264  return mustOverlap(other);
265 }
266 
268 {
269  sOutBuild->objStart("InvisibleLoc");
270 
271  sOutBuild->fieldStart("mMRE");
272  mMRE->output(pIR);
273  sOutBuild->fieldEnd("mMRE");
274 
275  sOutBuild->objEnd("InvisibleLoc");
276 }
277 
278 void InvisibleLoc::dump(std::ostream& os)
279 {
280  // string for mSymHandle
281  os << "InvisibleLoc(this=" << this << ", mMRE=";
282  mMRE->dump(os);
283  os << " )" << std::endl;
284 }
285 
286 
288 {
289  // string for mSymHandle
290  os << "InvisibleLoc(this=" << this << ", mMRE=";
291  mMRE->dump(os,pIR);
292  os << " )" << std::endl;
293 }
294 
296 {
297  std::ostringstream oss;
298  // string for mSymHandle
299  oss << "InvisibleLoc: ";
300  mMRE->dump(oss,pIR);
301  return oss.str();
302 }
303 
304 } // end namespace