OpenADFortTk (including Open64 and OpenAnalysis references)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DUGStandard.hpp
Go to the documentation of this file.
1 
15 //--------------------------------------------------------------------
16 //--------------------------------------------------------------------
17 
18 #ifndef DUGStandard_H
19 #define DUGStandard_H
20 
21 //--------------------------------------------------------------------
22 #define CONTEXT_SENSITIVITY
23 // #define DEBUG_DUAA
24 // #define DEBUG_PATH // to get a path for marking 'varied' or 'useful'
25 
26 //--------------------------------------------------------------------
27 // STL headers
28 #include <list>
29 #include <map>
30 
31 // OpenAnalysis headers
35 #include <OpenAnalysis/CFG/CFG.hpp>
43 //--------------------------------------------------------------------
44 
45 
46 namespace OA {
47  namespace DUG {
48 
49 class Node;
50 class Edge;
51 class NodesIterator;
52 class EdgesIterator;
53 class DUGStandard;
54 
55 //--------------------------------------------------------
56 class Node : public virtual NodeInterface {
57 public:
59  : mDUG(pDUG), mProc(proc), mType(pType) { Ctor(); }
62  : mDUG(pDUG), mProc(proc), mType(pType) { Ctor(); }
64  : mDUG(pDUG), mProc(pProc), mType(NONEFORMAL_NODE), mSym(pSym)
65  { Ctor(); }
66 
67  ~Node () { }
68 
69  //========================================================
70  // Info specific to DUG
71  //========================================================
72 
73  NodeType getType() const { return mType; }
75 
76  ProcHandle getProc() const { return mProc; }
77  OA_ptr<Location> getLoc() const { return mLoc; }
78  SymHandle getSym() const { return mSym; }
79 
80  void markVaried(std::list<CallHandle>&,
82  std::set<OA_ptr<EdgeInterface> >&,
83  std::set<std::pair<unsigned,unsigned> >&,
84  ProcHandle, unsigned,
86  bool activeWithVariedOnly);
87  void markUseful(std::list<CallHandle>&,
89  std::set<OA_ptr<EdgeInterface> >&,
90  std::set<std::pair<unsigned,unsigned> >&,
91  ProcHandle, unsigned,
93 
94  bool isVaried(){ return mVaried;}
95  void setVaried()
96  {
97  mVaried = true;
98  }
99  void unsetVaried()
100  {
101  mVaried = false;
102  }
103  bool isVariedContext(CallHandle context) const {
104  return mVariedContexts.find(context) != mVariedContexts.end(); }
106  mVariedContexts.insert(context); }
107 
108  bool isUseful(){ return mUseful;}
109  void setUseful(){ mUseful = true;};
110  void unsetUseful(){ mUseful = false;};
111 
112  void setActive();
113  void setActive(SymHandle);
114 
117 
119  std::set<OA_ptr<NodeInterface> >&);
120  bool hasEdgesToOtherProc(ProcHandle, std::set<SymHandle>&);
121  bool hasEdgesFromOtherProc(ProcHandle, std::set<SymHandle>&);
122  void findOutgoingNodes(ProcHandle, std::set<SymHandle>&, std::set<SymHandle>&);
123 // void findIncomingNodes(ProcHandle, std::set<SymHandle>&, std::set<SymHandle>&);
124 
125 
126  unsigned int size () const {
127  assert(0); //yet to be implemented PLM 09/19/06
128  return 0;
129  }
130 
131 
132  //========================================================
133  // DGraph::Interface::Node interface
134  //========================================================
135 
137  unsigned int getId() const
138  {
139  return mDGNode->getId();
140  //return mId;
141  }
142 
144  int num_incoming () const { return mDGNode->num_incoming(); }
145 
147  int num_outgoing () const { return mDGNode->num_outgoing(); }
148 
150  bool isAnEntry() const { return mDGNode->isAnEntry(); }
151 
153  bool isAnExit() const { return mDGNode->isAnExit(); }
154 
155  bool operator==(DGraph::NodeInterface& other);
156  bool operator<(DGraph::NodeInterface& other);
157 
158  //========================================================
159  // Output
160  //========================================================
161  void dump(std::ostream& os) { } // for full override
162  void dumpbase(std::ostream& os) {}
163  void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
164  void dumpdot(std::ostream& os, OA_ptr<DUGIRInterface> ir);
165  void longdump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
167 
168  mDGNode->output(ir);
169 
170  }
171 
172 public:
173  //========================================================
174  // These methods shadow the same named methods in
175  // the DGraph::Interface class and allow us to return
176  // the more specific subclass
177  //========================================================
179 
181 
183 
185 
187 
189 
191 
193 
194  //========================================================
195  // Construction
196  //========================================================
198  {
199  return mDGNode->addIncomingEdge(e);
200  }
201 
203  {
204  return mDGNode->addOutgoingEdge(e);
205  }
206 
208  {
209 
210  return mDGNode->removeIncomingEdge(e);
211  }
212 
214  {
215  return mDGNode->removeOutgoingEdge(e);
216  }
217 
218 private:
219  void Ctor();
220 
221 
222  unsigned int mId; // 0 is reserved; first instance is 1
223  OA_ptr<DUGStandard> mDUG; // enclosing DUG
224  ProcHandle mProc; // enclosing procedure
225  NodeType mType; // node type
226 
227  OA_ptr<DGraph::NodeImplement> mDGNode; // corresponding DGraph node
228  // in DGraph that keeps
229  // structure
230 
232  SymHandle mSym; // node key
233  bool mVaried; // 'true' if varied
234  bool mUseful; // 'true' if useful
235  bool mSelfDependent; // 'true' if the variable has a self dependence.
236  // - for context sensitivity between 'varied' and 'useful' analyses
237  // - For each actual parameter node, the contexts of RETURN edges along which
238  // 'varied' analysis has propagated are stored.
239  std::set<CallHandle> mVariedContexts;
240 
241  friend class DUGStandard;
242  friend class Edge;
243 };
244 
245 
246 
247 
248 //--------------------------------------------------------
249 class Edge : public virtual EdgeInterface {
250 public:
252  OA_ptr<Node> pNode1, OA_ptr<Node> pNode2, EdgeType pType,
253  CallHandle call, ProcHandle p);
254  ~Edge () {}
255 
256  //========================================================
257  // Info specific to DUG
258  //========================================================
259 
260  EdgeType getType() const { return mType; }
261 
262  ProcHandle getSourceProc() const { return mNode1->getProc(); }
263  ProcHandle getSinkProc() const { return mNode2->getProc(); }
264  CallHandle getCall() const { return mCall; }
265  ProcHandle getProc() const { return mProc; }
266 
267  // 090801: explore PARAM_EDGEs just once for each call context
268  bool isExplored4Varied(CallHandle context) const {
269  return mExplored4Varied.find(context) != mExplored4Varied.end(); }
271  mExplored4Varied.insert(context); }
272  bool isExplored4Useful(CallHandle context) const {
273  return mExplored4Useful.find(context) != mExplored4Useful.end(); }
275  mExplored4Useful.insert(context); }
276 
277  //========================================================
278  // DGraph::Interface::Edge interface
279  //========================================================
280 
282  unsigned int getId() const
283  {
284  return mDGEdge->getId();
285  }
286 
289  // FIXME: tail and head should be done like source and sink
290  // in DGraph::Interface and here
292 
296 
298  {
299  return getSource().convert<Node>();
300  }
301 
303  {
304  return getSink().convert<Node>();
305  }
306 
307 
308  bool operator==(DGraph::EdgeInterface& other);
309  bool operator<(DGraph::EdgeInterface& other);
310 
311  void dump (std::ostream& os);
312  void dumpdot (std::ostream& os, OA_ptr<DUGIRInterface> ir);
313  void dumpdot_label (std::ostream& os, OA_ptr<DUGIRInterface> ir);
314  void dumpbase (std::ostream& os) {}
316 
317 private:
318 
322 
324  CallHandle mCall; // for CALL and RETURN edges
325  unsigned int mId; // 0 is reserved; first instance is 1
326  ProcHandle mProc; // proc where this edge is used
327 
328  friend class DUGStandard;
329  friend class Node;
330 
331  // 090801: store visit information to remove exponential growth
332  // in number of PARAM_EDGEs
333  std::set<CallHandle> mExplored4Varied;
334  std::set<CallHandle> mExplored4Useful;
335 };
336 
337 //------------------------------------------------------------------
342  public virtual NodesIteratorInterface
343 {
344 public:
346  : DGraph::NodesIteratorImplement(ni) { }
347 
349 
351 
352 };
353 
354 //------------------------------------------------------------------
359  public virtual EdgesIteratorInterface
360 {
361 public:
363  : DGraph::EdgesIteratorImplement(ni) { }
364 
366 
368 
369 };
370 
371 
372 //------------------------------------------------------------------
373 class DUGStandard : public virtual DUGInterface
374 {
375 public:
376 
377  friend class Node;
378 
379  DUGStandard (
382  virtual ~DUGStandard ();
383 
384  //-------------------------------------
385  // DUG information access
386  //-------------------------------------
387 
391 
395 
396  std::list<std::pair<SymHandle, ProcHandle> >& getIndepSyms(){
397  return mIndepSymList;
398  }
399  std::list<std::pair<SymHandle, ProcHandle> >& getDepSyms(){
400  return mDepSymList;
401  }
402 
404  mIndepSymList.push_back(std::pair<SymHandle, ProcHandle>(sym, proc));
405  mIndepSymSet.insert(sym);
406  }
407 
409  mDepSymList.push_back(std::pair<SymHandle, ProcHandle>(sym, proc));
410  mDepSymSet.insert(sym);
411  }
412 
414 
415  mSymToProc[sym] = proc;
416  }
417 
419 #ifdef DEBUG_DUAA
420  std::cout << "DUGStandard::insertActiveSymSet:(sym: ";
421  std::cout << sym << " )" << std::endl;
422 #endif
423  mActiveSymSet->insert(sym);
424  }
425 
426  std::map<ProcHandle,OA_ptr<OA::Activity::ActiveStandard> >& getActiveMap(){
427  return mActiveMap;
428  }
429 
431  return mActiveSymSet;
432  }
434 
437  if (mIndepSymSet.find(sym) != mIndepSymSet.end()) return true;
438 
439  OA_ptr<Location> loc = mIR->getLocation(proc, sym);
440  if (loc.ptrEqual(0)) return false;
441  OA_ptr<NamedLoc> nloc = loc.convert<NamedLoc>();
442  OA_ptr<SymHandleIterator> symIter = nloc->getFullOverlapIter();
443  for ( ; symIter->isValid(); (*symIter)++) {
444  SymHandle temp = symIter->current();
445  if (mIndepSymSet.find(temp) != mIndepSymSet.end()) return true;
446  }
447  return false;
448  }
449 
452  if (mDepSymSet.find(sym) != mDepSymSet.end()) return true;
453 
454  OA_ptr<Location> loc = mIR->getLocation(proc, sym);
455  if (loc.ptrEqual(0)) return false;
456  OA_ptr<NamedLoc> nloc = loc.convert<NamedLoc>();
457  OA_ptr<SymHandleIterator> symIter = nloc->getFullOverlapIter();
458  for ( ; symIter->isValid(); (*symIter)++) {
459  SymHandle temp = symIter->current();
460  if (mDepSymSet.find(temp) != mDepSymSet.end()) return true;
461  }
462  return false;
463  }
464 
466  bool isActive(SymHandle sym);
467 
469  bool isActive(StmtHandle stmt);
470 
472  bool isActive(MemRefHandle memref);
473 
475  mActiveStmtSet->insert(stmt);
476  mActiveMap[proc]->insertStmt(stmt);
477  }
478 
479 
481  mActiveMemRefSet->insert(mref);
482  mActiveMap[proc]->insertMemRef(mref);
483  }
484 
486 
487  if (mActiveMap[proc].ptrEqual(0)) {
488  mActiveMap[proc] = new OA::Activity::ActiveStandard(proc);
489  }
490  }
491 
492  //========================================================
493  // Construction
494  //========================================================
495 
496 
499 
500 
501  //========================================================
502  // DGraph::Interface::Edge interface
503  //========================================================
504 
505  int getNumNodes () { return mDGraph->getNumNodes(); }
506  int getNumEdges () { return mDGraph->getNumEdges(); }
507 
508 
509  // Output Functionalities
510  void dump (std::ostream& os, OA_ptr<IRHandlesIRInterface> ir);
511  void dumpdot (std::ostream& os, OA_ptr<DUGIRInterface> ir);
512  void dumpbase(std::ostream& os) {}
514 
515 
516  //------------------------------------------------------------------
517  // Using trick of imitating covariance when getting all iterators
518  // so that get an iterator specific to actual subclass
519  // This is why have these getBlahIterator methods that shadow those
520  // in DGraph::Interface and also have the protected ones
521  // that must be defined here which override implementation in
522  // DGraph::Interface
523  //------------------------------------------------------------------
524 
526 
528 
530 
532 
534 
536 
539 
543 
546 
550 
551 
552  //==================================================================
553 
555  getDUGNodesIterator() const;
556 
558  getDUGEdgesIterator() const;
559 
561  getDUGEntryNodesIterator() const;
562 
564  getDUGExitNodesIterator() const;
565 
568 
571 
574  mSymToMemRefSet[sym].insert(mref);
575  }
576 
579  mSymToStmtSet[sym].insert(stmt);
580  }
581 
584  std::set<MemRefHandle> getMemRefSet(SymHandle sym) {
585  return mSymToMemRefSet[sym];
586  }
587 
590  std::set<StmtHandle> getStmtSet(SymHandle sym) {
591  return mSymToStmtSet[sym];
592  }
593 
594  //==================================================================
595 
597  bool isNode(SymHandle, ProcHandle);
598 
599 private:
602 
603  // dgraph that will store underlying graph structure
604  // OA_ptr<DGraph::DGraphImplement> mDGraph;
605 
607 
608  // using lists instead of sets because some of the iterators
609  // need an ordered list of things and only want to have one
610  // NodeIterator and EdgesIterator implementation
613 
614  // map from SymHandle to Node
615  std::map<SymHandle, OA_ptr<Node> > mSymToNode;
616 
617  // map from SymHandle to Location
618  std::map<SymHandle, OA_ptr<Location> > mSymToLoc;
619  std::map<SymHandle, ProcHandle> mSymToProc;
620 
621  // DUAA specific
623  //OA_ptr<IRHandlesIRInterface> mIR;
625 
626 
627  std::list<std::pair<SymHandle, ProcHandle> > mIndepSymList;
628  std::list<std::pair<SymHandle, ProcHandle> > mDepSymList;
629  std::set<SymHandle> mIndepSymSet;
630  std::set<SymHandle> mDepSymSet;
631 
635  std::map<ProcHandle,OA_ptr<OA::Activity::ActiveStandard> > mActiveMap;
636 
638 
639 
640 
641  std::map<SymHandle, std::set<MemRefHandle> > mSymToMemRefSet;
642 
643  std::map<SymHandle, std::set<StmtHandle> > mSymToStmtSet;
644 
645  std::map<OA_ptr<Location>, OA_ptr<std::set<MemRefHandle> > > mLocToMemRefSet;
646 
647  std::map<OA_ptr<Location>, OA_ptr<std::set<StmtHandle> > > mLocToStmtSet;
648 
649 };
650 //--------------------------------------------------------------------
651 
652  } // end of DUG namespace
653 } // end of OA namespace
654 
655 #endif