OpenADFortTk (including Open64 and OpenAnalysis references)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ManagerSideEffectStandard.cpp
Go to the documentation of this file.
1 
18 #include <Utils/Util.hpp>
19 
20 
21 namespace OA {
22  namespace SideEffect {
23 
24 static bool debug = false;
25 
34 /* Deprecated, replace functionality if necessary MMS 7/6/06
35 class RefVisitor : public virtual LocationVisitor {
36  private:
37  std::set<SymHandle>& mRefSymSet;
38  public:
39  bool mRef;
40 
41  RefVisitor(std::set<SymHandle> &pRefSymSet)
42  : mRefSymSet(pRefSymSet), mRef(true) {}
43  ~RefVisitor() {}
44  void visitNamedLoc(NamedLoc& loc)
45  {
46  if (mRefSymSet.find(loc.getSymHandle()) != mRefSymSet.end())
47  { mRef = true; }
48  else { mRef = false; }
49  }
50  void visitUnnamedLoc(UnnamedLoc& loc) { mRef = true; }
51  void visitInvisibleLoc(InvisibleLoc& loc) { mRef = true; }
52  void visitUnknownLoc(UnknownLoc& loc) { mRef = true; }
53  void visitLocSubSet(LocSubSet& loc) {
54  // have this visitor visit the base location
55  OA_ptr<Location> baseLoc = loc.getLoc();
56  baseLoc->acceptVisitor(*this);
57  }
58 };
59 */
60 
62 {
63  OA_DEBUG_CTRL_MACRO("DEBUG_ManagerSideEffectStandard:ALL", debug);
64 }
65 
66 
79 {
80  mProc = proc;
81  if (debug) {
82  std::cout << "ManagerSideEffectStandard: proc = " << mIR->toString(proc)
83  << std::endl;
84  }
85 
86  // create a new (waiting to be filled) SideEffectStandard as member
87  OA_ptr<SideEffectStandard> retSideEffect;
88  retSideEffect= new SideEffectStandard();
89 
90  //alias->dump(std::cout,mIR);
91 
92  // empty out all the sets
93  retSideEffect->emptyLMOD();
94  retSideEffect->emptyMOD();
95  retSideEffect->emptyLDEF();
96  retSideEffect->emptyDEF();
97  retSideEffect->emptyLUSE();
98  retSideEffect->emptyUSE();
99  retSideEffect->emptyLREF();
100  retSideEffect->emptyREF();
101 
102  // loop through statements
103  OA_ptr<OA::IRStmtIterator> sIt = mIR->getStmtIterator(proc);
104  for ( ; sIt->isValid(); (*sIt)++) {
105  OA::StmtHandle stmt = sIt->current();
106  if (debug) {
107  std::cout << "\tstmt = ";
108  mIR->dump(stmt,std::cout);
109  }
110 
111  // for each use memory reference in the stmt
112  OA_ptr<MemRefHandleIterator> mrIterPtr = mIR->getUseMemRefs(stmt);
113  for (; mrIterPtr->isValid(); (*mrIterPtr)++ )
114  {
115  MemRefHandle memref = mrIterPtr->current();
116  if (debug) {
117  std::cout << "\tmemref = ";
118  mIR->dump(memref,std::cout);
119  }
120 
121  // each location the memory reference may reference
122  OA_ptr<LocIterator> locIterPtr = alias->getMayLocs(memref);
123  for (; locIterPtr->isValid(); ++(*locIterPtr)) {
124 
125  OA_ptr<Location> useLoc = locIterPtr->current();
126  if (debug) {
127  std::cout << "useLoc = ";
128  useLoc->dump(std::cout, mIR);
129  }
130 
131  // DEPRECATED, no longer necessary, alias analysis only maps
132  // to locations visible within the procedure, MMS 7/6/06
133  // will only put into these sets if the location is referenced
134  // in the procedure
135  //useLoc->acceptVisitor(refVisitor);
136  //if (refVisitor.mRef == true) {
137 
138  // put each location used through a memory reference in LREF and REF
139  retSideEffect->insertLREF( useLoc);
140  retSideEffect->insertREF( useLoc);
141 
142  // put each location used through a memory reference in LUSE
143  // and USE if the location is not already in DEF
144  // FIXME?: assuming everything is used in a statement before
145  // anything
146  // is defined, is this not the case in things like short circuits?
147 
148  // CONSERVATIVE FIXME: just do all USEs, to do upward exposed need
149  // CFG, to do only USEd, need to calc DEF first
150  //if (!retSideEffect->inDEF(useLoc)) {
151 
152  retSideEffect->insertLUSE(useLoc);
153  retSideEffect->insertUSE(useLoc);
154  // }
155  //}
156  }
157  }
158 
159  // for each def memory reference in the stmt
160  mrIterPtr = mIR->getDefMemRefs(stmt);
161  for (; mrIterPtr->isValid(); (*mrIterPtr)++ )
162  {
163  MemRefHandle memref = mrIterPtr->current();
164  if (debug) {
165  std::cout << "\tmemref = ";
166  mIR->dump(memref,std::cout);
167  }
168 
169  // put each location may defined into LMOD and MOD
170  OA_ptr<LocIterator> locIterPtr = alias->getMayLocs(memref);
171  for (; locIterPtr->isValid(); ++(*locIterPtr)) {
172  OA_ptr<Location> mayDef = locIterPtr->current();
173  if (debug) {
174  std::cout << "mayDef = ";
175  mayDef->dump(std::cout, mIR);
176  }
177 
178  // AGAIN, DEPRECATED
179  // will only put into these sets if the location is referenced
180  // in the procedure
181  //mayDef->acceptVisitor(refVisitor);
182  //if (refVisitor.mRef == true) {
183  retSideEffect->insertLMOD(mayDef);
184  retSideEffect->insertMOD(mayDef);
185  //}
186  }
187 
188  // put each location must defined into LDEF and DEF
189  locIterPtr = alias->getMustLocs(memref);
190  for (; locIterPtr->isValid(); ++(*locIterPtr)) {
191  OA_ptr<Location> mustDef = locIterPtr->current();
192 
193  // will only put into these sets if the location is referenced
194  // in the procedure
195  //mustDef->acceptVisitor(refVisitor);
196  //if (refVisitor.mRef == true) {
197  retSideEffect->insertLDEF(mustDef);
198  retSideEffect->insertDEF(mustDef);
199  //}
200  }
201  }
202 
203  // Iterate over procedure calls of a statement
204  // to determine their effect
205  OA_ptr<IRCallsiteIterator> callsiteItPtr = mIR->getCallsites(stmt);
206  for ( ; callsiteItPtr->isValid(); ++(*callsiteItPtr)) {
207  CallHandle call = callsiteItPtr->current();
208  if (debug) {
209  std::cout << "\tcall = " << mIR->toString(call) << std::endl;
210  }
211 
212  OA_ptr<LocIterator> locIterPtr;
213 
214  // MOD
215  locIterPtr = inter->getMODIterator(call);
216  for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
217  retSideEffect->insertMOD(locIterPtr->current());
218  if (debug) {
219  std::cout << "\tinserting loc = ";
220  locIterPtr->current()->dump(std::cout,mIR);
221  std::cout << "\tinto MOD" << std::endl;
222  }
223  }
224  // DEF
225  locIterPtr = inter->getDEFIterator(call);
226  for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
227  retSideEffect->insertDEF(locIterPtr->current());
228  }
229  // USE
230  locIterPtr = inter->getUSEIterator(call);
231  for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
232  //if (!retSideEffect->inDEF(locIterPtr->current())) {
233  //FIXME: don't know order of use vs def in func call
234  OA_ptr<Location> Loc = locIterPtr->current();
235  if (debug) {
236  std::cout << "SideEffectStandard USE retSideEffect = ";
237  Loc->dump(std::cout);
238  std::cout << std::endl;
239  }
240  retSideEffect->insertUSE(Loc);
241  // retSideEffect->insertUSE(locIterPtr->current());
242  //}
243  }
244  // REF
245  locIterPtr = inter->getREFIterator(call);
246  for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
247  retSideEffect->insertREF(locIterPtr->current());
248  }
249  }
250 
251  } // end of loop over statements
252 
253  return retSideEffect;
254 }
255  } // end of namespace SideEffect
256 } // end of namespace OA