OpenADFortTk (including Open64 and OpenAnalysis references)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MemRefExpr.hpp
Go to the documentation of this file.
1 
15 #ifndef MemRefExpr_H
16 #define MemRefExpr_H
17 
18 #include <iostream>
19 #include <cassert>
23 
24 namespace OA {
25 
26 class MemRefExpr;
27 class IdxExprAccess;
28 class MemRefExpr;
29 class NamedRef;
30 class UnnamedRef;
31 class UnknownRef;
32 class RefOp;
33 class Deref;
34 class SubSetRef;
35 class IdxAccess;
36 class IdxExprAccess;
37 class FieldAccess;
38 
39 class MemRefExprVisitor;
40 
41 // ----- Iterator classes -----
42 template<class T>
44  public:
46  virtual ~MREIteratorClass() { }
47 
48  // Returns the current item.
49  virtual OA_ptr<T> current() const = 0;
50 
51  // False when all items are exhausted.;
52  virtual bool isValid() const = 0;
53 
54  virtual void operator++() = 0;
55  void operator++(int) { ++*this; } ;
56 
57  virtual void reset() = 0;
58 };
59 
70 
71 // ------ MemRefExpr classes -----
72 
76 class MemRefExpr : public Annotation {
77  public:
78  typedef enum {
79  USE, // mem ref specifies where to find source location for use
80  DEF, // mem ref specifies where to put result of assign
81  USEDEF, // mem ref that specifies a location that will be used first
82  // and then defined (eg. i++)
83  DEFUSE // mem ref that specifies a location that will be defined first
84  // and then used (eg. i++)
85  } MemRefType;
86 
87  MemRefExpr(MemRefType mrType) : mMemRefType(mrType) {}
88 
91 
92  virtual ~MemRefExpr() {}
93 
94  virtual void acceptVisitor(MemRefExprVisitor& pVisitor) = 0;
95 
96  // return a ptr to a copy of self
97  virtual OA_ptr<MemRefExpr> clone() = 0;
98 
99  //*****************************************************************
100  // Subclass type methods
101  //*****************************************************************
102  virtual bool isaNamed() { return false; }
103  virtual bool isaUnnamed() { return false; }
104  virtual bool isaUnknown() { return false; }
105  virtual bool isaRefOp() { return false; }
106 
107  virtual bool isaDeref() { return false; }
108  virtual bool isaAddressOf() { return false; }
109 
110  virtual bool isaSubSetRef() { return false; }
111  virtual bool isaIdxAccess() { return false; }
112  virtual bool isaIdxExprAccess() { return false; }
113  virtual bool isaFieldAccess() { return false; }
114 
115  //*****************************************************************
116  // Info methods
117  //*****************************************************************
118 
121 
123  bool isDef() { return (mMemRefType==DEF
124  || mMemRefType == USEDEF || mMemRefType == DEFUSE); }
125 
127  bool isUse() { return (mMemRefType==USE
128  || mMemRefType == USEDEF || mMemRefType == DEFUSE); }
129 
131  bool isDefUse() { return (mMemRefType==DEFUSE); }
132 
134  bool isUseDef() { return (mMemRefType==USEDEF); }
135 
136  //*****************************************************************
137  // Construction methods
138  //*****************************************************************
139 
142 
143  //*****************************************************************
144  // Relationship methods
145  //*****************************************************************
146 
148  virtual bool operator<(MemRefExpr & other);
149 
152  virtual bool operator==(MemRefExpr& other);
153 
156  bool operator!=(MemRefExpr& other) { return ! ((*this)==other); }
157 
158  //*****************************************************************
159  // Annotation Interface
160  //*****************************************************************
161  void output(IRHandlesIRInterface& ir);
162 
163  // helper functions for output
164  virtual std::string typeString() { return "MemRefExpr"; }
166 
167  //*****************************************************************
168  // Debugging methods
169  //*****************************************************************
170  virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR);
171  virtual void dump(std::ostream& os, IRHandlesIRInterface& pIR);
172  virtual void dump(std::ostream& os);
173 
174  virtual int getOrder() { assert(0); return sOrder; }
175 
176 private:
177  static const int sOrder = -100;
179 };
180 
185 class NamedRef: public MemRefExpr {
186  public:
187 
189  : MemRefExpr(mrType), mSymHandle(sh) { }
190 
193 
195 
196  ~NamedRef() { }
197 
198  void acceptVisitor(MemRefExprVisitor& pVisitor);
199 
202 
203  //*****************************************************************
204  // Subclass type methods
205  //*****************************************************************
206  bool isaNamed() { return true; }
207 
208  //*****************************************************************
209  // Info methods
210  //*****************************************************************
212  virtual std::string typeString() { return "NamedRef"; }
213 
214  //*****************************************************************
215  // Relationship methods
216  //*****************************************************************
217 
218  bool operator<(MemRefExpr & other);
219 
222  bool operator==(MemRefExpr& other);
223 
224  //*****************************************************************
225  // Annotation Interface
226  //*****************************************************************
227  void output(IRHandlesIRInterface& ir);
228 
229  //*****************************************************************
230  // Debugging methods
231  //*****************************************************************
232  virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR);
233  virtual void dump(std::ostream& os, IRHandlesIRInterface& pIR);
234  virtual void dump(std::ostream& os);
235 
236  virtual int getOrder() { return sOrder; }
237 
238  private:
239  static const int sOrder = 100;
241 };
242 
247 class UnnamedRef: public MemRefExpr {
248  public:
249 
251  : MemRefExpr(mrType), mExprHandle(sh), mLocal(true), mProcHandle(proc) { }
252 
253 
255  : MemRefExpr(mrType), mExprHandle(sh), mLocal(false) { }
256 
257 
261  mLocal(mre.mLocal),
262  mProcHandle(mre.mProcHandle) {}
263 
265  : MemRefExpr(mre), mExprHandle(s), mLocal(true), mProcHandle(p) {}
266 
267 
269  : MemRefExpr(mre), mExprHandle(s), mLocal(false) {}
270 
271 
273 
274  void acceptVisitor(MemRefExprVisitor& pVisitor);
275 
278 
279  //*****************************************************************
280  // Subclass type methods
281  //*****************************************************************
282  bool isaUnnamed() { return true; }
283 
284  //*****************************************************************
285  // Info methods
286  //*****************************************************************
288 
289  bool isLocal() { return mLocal; }
290 
292 
293  //*****************************************************************
294  // Relationship methods
295  //*****************************************************************
296 
297  bool operator<(MemRefExpr & other);
298 
301  bool operator==(MemRefExpr& other);
302 
303  //*****************************************************************
304  // Annotation Interface
305  //*****************************************************************
306  void output(IRHandlesIRInterface& ir);
307  virtual std::string typeString() { return "UnnamedRef"; }
308 
309  //*****************************************************************
310  // Debugging methods
311  //*****************************************************************
312  virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR);
313  virtual void dump(std::ostream& os, IRHandlesIRInterface& pIR);
314  virtual void dump(std::ostream& os);
315 
316  virtual int getOrder() { return sOrder; }
317 
318  private:
319  static const int sOrder = 200;
321  bool mLocal;
323 };
324 
330 class UnknownRef: public MemRefExpr {
331  public:
332 
334  : MemRefExpr(mrType) { }
335 
338 
340 
341  void acceptVisitor(MemRefExprVisitor& pVisitor);
342 
345 
346  //*****************************************************************
347  // Subclass type methods
348  //*****************************************************************
349  bool isaUnknown() { return true; }
350 
351  //*****************************************************************
352  // Relationship methods
353  //*****************************************************************
354 
355  bool operator<(MemRefExpr & other);
356 
359  bool operator==(MemRefExpr& other);
360 
361  //*****************************************************************
362  // Annotation Interface
363  //*****************************************************************
364  void output(IRHandlesIRInterface& ir);
365  virtual std::string typeString() { return "UnknownRef"; }
366 
367  //*****************************************************************
368  // Debugging methods
369  //*****************************************************************
370  virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR);
371  virtual void dump(std::ostream& os, IRHandlesIRInterface& pIR);
372  virtual void dump(std::ostream& os);
373 
374  virtual int getOrder() { return sOrder; }
375 
376  private:
377  static const int sOrder = 100000000;
378 };
379 
380 
387 class RefOp: public MemRefExpr {
388  public:
389 
391  : MemRefExpr(mrType), mMRE(mre) { }
392 
393 
395  RefOp(RefOp & mre) : MemRefExpr(mre), mMRE(mre.mMRE) { }
396 
397  virtual ~RefOp() { }
398 
399  //*****************************************************************
400  // MemRefExpr subclass type methods
401  //*****************************************************************
402  bool isaRefOp() { return true; }
403 
404  //*****************************************************************
405  // Info methods
406  //*****************************************************************
410 
411  virtual std::string typeString() { return "RefOp"; }
412 
416 
419 
420  //*****************************************************************
421  // Relationship methods, will be defined in subclasses
422  //*****************************************************************
423 
424  //*****************************************************************
425  // Construction Method
426  //*****************************************************************
427 
430 
431  //*****************************************************************
432  // Annotation Interface
433  //*****************************************************************
434  virtual void output(IRHandlesIRInterface& ir);
435 
436 
437 private:
439 
440 };
441 
442 
443 /* AddressOf class: represents if MemRefExpr has AddressTaken*/
444 class AddressOf: public RefOp {
445  public:
446 
448  : RefOp(mrType, mre) { }
449 
451  AddressOf(AddressOf & mre) : RefOp(mre) { }
452 
453  ~AddressOf() { }
454 
455  void acceptVisitor(MemRefExprVisitor& pVisitor);
456 
459 
460  virtual std::string typeString() { return "AddressOf"; }
461 
462  //*****************************************************************
463  // RefOp subclass type methods
464  //*****************************************************************
465  bool isaAddressOf() { return true; }
466 
467  //*****************************************************************
468  // Relationship methods
469  //*****************************************************************
470 
471  bool operator<(MemRefExpr & other);
472 
475  bool operator==(MemRefExpr& other);
476 
477  //*****************************************************************
478  // Construction Method
479  //*****************************************************************
482 
483  //*****************************************************************
484  // Annotation Interface
485  //*****************************************************************
486  void output(IRHandlesIRInterface& ir);
487 
488  //*****************************************************************
489  // Debugging methods
490  //*****************************************************************
491  virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR);
492  virtual void dump(std::ostream& os, IRHandlesIRInterface& pIR);
493  virtual void dump(std::ostream& os);
494 
495  virtual int getOrder() { return sOrder; }
496 
497  private:
498  static const int sOrder = 350;
499 };
500 
501 
506 class Deref: public RefOp {
507  public:
508 
510  int numDeref)
511  : RefOp(mrType, mre), mNumDeref(numDeref) { }
512 
513 
514  // default values
516  : RefOp(mrType, mre), mNumDeref(1) { }
517 
518 
520  Deref(Deref &mre) : RefOp(mre), mNumDeref(mre.mNumDeref) {}
521 
522  ~Deref() { }
523 
524  void acceptVisitor(MemRefExprVisitor& pVisitor);
525 
528 
529  //*****************************************************************
530  // RefOp subclass type methods
531  //*****************************************************************
532  bool isaDeref() { return true; }
533 
534  //*****************************************************************
535  // Info methods
536  //*****************************************************************
537  int getNumDerefs() { return mNumDeref; }
538  virtual std::string typeString() { return "Deref"; }
539 
540  //*****************************************************************
541  // Relationship methods
542  //*****************************************************************
543 
544  bool operator<(MemRefExpr & other);
545 
548  bool operator==(MemRefExpr& other);
549 
550  //*****************************************************************
551  // Construction Method
552  //*****************************************************************
553 
556 
557  //*****************************************************************
558  // Annotation Interface
559  //*****************************************************************
560  void output(IRHandlesIRInterface& ir);
561 
562  //*****************************************************************
563  // Debugging methods
564  //*****************************************************************
565  virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR);
566  virtual void dump(std::ostream& os, IRHandlesIRInterface& pIR);
567  virtual void dump(std::ostream& os);
568 
569  virtual int getOrder() { return sOrder; }
570 
571 private:
572  static const int sOrder = 300;
574 };
575 
583 class SubSetRef: public RefOp {
584  public:
585 
587  : RefOp(mrType, mre) {} //{ if (!mre.ptrEqual(0)) assert( ! mre->isaSubSetRef() ); }
588 
590  SubSetRef(SubSetRef & mre) : RefOp(mre) { }
591 
592  virtual ~SubSetRef() { }
593 
594  void acceptVisitor(MemRefExprVisitor& pVisitor);
595 
598 
599  //*****************************************************************
600  // RefOp subclass type methods
601  //*****************************************************************
602  virtual bool isaSubSetRef() { return true; }
603  virtual bool isSubClassOfSubSetRef() { return false; }
604 
605  //*****************************************************************
606  // Relationship methods, will be defined in subclasses
607  //*****************************************************************
608 
609  virtual bool operator<(MemRefExpr & other);
610 
613  virtual bool operator==(MemRefExpr& other);
614 
615  //*****************************************************************
616  // Construction Method
617  //*****************************************************************
618 
621 
622  //*****************************************************************
623  // Annotation Interface
624  //*****************************************************************
625  void output(IRHandlesIRInterface& ir);
626  virtual std::string typeString() { return "SubSetRef"; }
627 
628  //*****************************************************************
629  // Debugging methods
630  //****************************************************************
631  virtual void dump(std::ostream& os,
633 
634  virtual void dump(std::ostream& os, IRHandlesIRInterface& pIR);
635  virtual void dump(std::ostream& os);
636  virtual int getOrder() { return sOrder; }
637 
638 private:
639  static const int sOrder = 600;
640 
641 };
642 
643 
647 class IdxAccess: public SubSetRef {
648  public:
649 
651  : SubSetRef(mrType,mre), mIdx(idx) { }
652 
654  IdxAccess(IdxAccess &mre) : SubSetRef(mre), mIdx(mre.mIdx) {}
655 
657 
658  void acceptVisitor(MemRefExprVisitor& pVisitor);
659 
662 
663  //*****************************************************************
664  // SubSetRef subclass type methods
665  //*****************************************************************
666  bool isaIdxAccess() { return true; }
667  bool isSubClassOfSubSetRef() { return true; }
668 
669  //*****************************************************************
670  // Info methods
671  //*****************************************************************
672  int getIdx() { return mIdx; }
673  virtual std::string typeString() { return "IdxAccess"; }
674 
675  //*****************************************************************
676  // Relationship methods
677  //*****************************************************************
678 
679  bool operator<(MemRefExpr & other);
680 
683  bool operator==(MemRefExpr& other);
684 
685  //*****************************************************************
686  // Annotation Interface
687  //*****************************************************************
688  void output(IRHandlesIRInterface& ir);
689 
690  //*****************************************************************
691  // Debugging methods
692  //*****************************************************************
693  virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR);
694  virtual void dump(std::ostream& os, IRHandlesIRInterface& pIR);
695  virtual void dump(std::ostream& os);
696 
697  virtual int getOrder() { return sOrder; }
698 
699 private:
700  static const int sOrder = 400;
701  int mIdx;
702 };
703 
710 class IdxExprAccess : public SubSetRef {
711  public:
712 
714  MemRefHandle hExpr)
715  : SubSetRef( mrType, mre)
716  {
717  mhExpr = hExpr;
718  }
719 
722  : SubSetRef(mre),
723  mhExpr(mre.mhExpr)
724  {
725  }
726 
728 
729  virtual void acceptVisitor(MemRefExprVisitor& pVisitor);
730 
733 
734  //*****************************************************************
735  // SubSetRef subclass type methods
736  //*****************************************************************
737  bool isaIdxExprAccess() { return true; }
738  bool isSubClassOfSubSetRef() { return true; }
739 
740  //*****************************************************************
741  // Info methods
742  //*****************************************************************
744  virtual std::string typeString() { return "IdxExprAccess"; }
745 
746  //*****************************************************************
747  // Relationship methods
748  //*****************************************************************
749  bool operator<(MemRefExpr & other);
750 
753  bool operator==(MemRefExpr& other);
754 
755  //*****************************************************************
756  // Annotation Interface
757  //*****************************************************************
758  void output(IRHandlesIRInterface& ir);
759 
760  //*****************************************************************
761  // Debugging methods
762  //*****************************************************************
763  virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR);
764  virtual void dump(std::ostream& os, IRHandlesIRInterface& pIR);
765  virtual void dump(std::ostream& os);
766 
767  virtual int getOrder() { return sOrder; }
768 
769  private:
770  static const int sOrder = 450;
772 };
773 
778 class FieldAccess: public SubSetRef {
779  public:
780 
782  OA_ptr<MemRefExpr> mre, std::string field)
783  : SubSetRef(mrType,mre), mFieldName(field) { }
784 
785 
788 
790 
791  void acceptVisitor(MemRefExprVisitor& pVisitor);
792 
795 
796  //*****************************************************************
797  // SubSetRef subclass type methods
798  //*****************************************************************
799  bool isaFieldAccess() { return true; }
800  bool isSubClassOfSubSetRef() { return true; }
801 
802  //*****************************************************************
803  // Info methods
804  //*****************************************************************
806  virtual std::string typeString() { return "FieldAccess"; }
807 
808  //*****************************************************************
809  // Relationship methods
810  //*****************************************************************
811 
812  bool operator<(MemRefExpr & other);
813 
816  bool operator==(MemRefExpr& other);
817 
818  //*****************************************************************
819  // Annotation Interface
820  //*****************************************************************
821  void output(IRHandlesIRInterface& ir);
822 
823  //*****************************************************************
824  // Debugging methods
825  //*****************************************************************
826  virtual void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> pIR);
827  virtual void dump(std::ostream& os, IRHandlesIRInterface& pIR);
828  virtual void dump(std::ostream& os);
829 
830  virtual int getOrder() { return sOrder; }
831 
832 private:
833  static const int sOrder = 500;
835 };
836 
837 
838 } // end of OA namespace
839 
840 #endif
841