OpenADFortTk (including Open64 and OpenAnalysis references)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
WhirlIDMaps.h
Go to the documentation of this file.
1 // ##########################################################
2 // # This file is part of OpenADFortTk. #
3 // # The full COPYRIGHT notice can be found in the top #
4 // # level directory of the OpenADFortTk source tree. #
5 // # For more information visit #
6 // # http://www.mcs.anl.gov/openad #
7 // ##########################################################
8 
9 #ifndef WhirlIDMaps_INCLUDED_h
10 #define WhirlIDMaps_INCLUDED_h
11 
12 #include <iostream>
13 #include <map> // STL
14 #include <set> // STL
15 #include <list> // STL
16 
18 
19 #include "BaseMap.h"
20 #include "Diagnostics.h"
21 
22 
23 namespace fortTkSupport {
24 
25 typedef UINT SymTabId;
26 typedef UINT SymId;
27 typedef UINT PUId;
28 typedef UINT WNId;
29 
30 // A list of ids: Should only be used with scalar id types above
31 template <class T>
32 class IdList : public std::list<T> {
33 public:
34  IdList() { }
35  ~IdList() { }
36 
37  // Returns 0 if not found
38  T Find(T id) const
39  {
40  typename std::list<T>::iterator it;
41  for (it = this->begin(); it != this->end(); ++it) {
42  T val = *it;
43  if (id == val) { return val; }
44  }
45  return 0;
46  }
47 
48 };
49 
50 
51 //***************************************************************************
52 // ST_TAB <-> SymTabId maps (global/interprocedural)
53 //***************************************************************************
54 
56  : public BaseMap<ST_TAB*, SymTabId>
57 {
58 public:
60  SymTabToSymTabIdMap(PU_Info* pu_forest) { Create(pu_forest); }
61  virtual ~SymTabToSymTabIdMap() { }
62 
63  void Create(PU_Info* pu_forest);
64 };
65 
66 
67 // SymTabIdToSymTabMap: In WHIRL, all ST_TAB* are associated with a
68 // specific PU_Info*, except the global ST_TAB*. Because of the way
69 // the symbol table is implemented, it is usually not easy to access the
70 // symbol table with the ST_TAB*: one needs the corresponding
71 // PU_Info*. Consequently, we map a SymTabId to a pair. When
72 // entering the global the global ST_TAB* in the map, PU_Info* should
73 // be NULL.
75  : public std::map<SymTabId, pair<ST_TAB*, PU_Info*> > {
76 
77 protected:
78  typedef std::map<SymTabId, pair<ST_TAB*, PU_Info*> > BaseMap;
79 
80 public:
82  SymTabIdToSymTabMap(PU_Info* pu_forest) { Create(pu_forest); }
83  virtual ~SymTabIdToSymTabMap() { }
84 
85  pair<ST_TAB*, PU_Info*>
86  Find(SymTabId id, bool mustFind = false) const
87  {
88  pair<ST_TAB*, PU_Info*> result(NULL, NULL);
89 
90  const_iterator it = this->find(id);
91  if (it != this->end()) {
92  result = (*it).second;
93  }
94  else if (mustFind) {
95  FORTTK_DIE("SymTabIdToSymTabMap: Could not find entry for key '"
96  << id << "'");
97  }
98 
99  return result;
100  }
101 
102  void
103  Insert(SymTabId id, ST_TAB* stab, PU_Info* pu)
104  {
105  this->insert(make_pair(id, make_pair(stab, pu))); // do not add duplicates!
106  }
107 
108  void Create(PU_Info* pu_forest);
109 };
110 
111 
112 //***************************************************************************
113 // ST <-> SymId maps (intra-procedural)
114 //***************************************************************************
115 
116 // Note: Instead of creating ST* <-> to SymId maps, we currently use a
117 // ST's index -- ST_index(ST*) -- in the symbol table as a persistent
118 // id. While this is correct, it would be nice to add an interface
119 // map, even if the map is really only the identity function without
120 // any state.
121 
122 
123 //***************************************************************************
124 // PU <-> PUId maps (global/interprocedural)
125 //***************************************************************************
126 
128  : public BaseMap<PU_Info*, PUId>
129 {
130 public:
132  PUToPUIdMap(PU_Info* pu_forest) { Create(pu_forest); }
133  virtual ~PUToPUIdMap() { }
134 
135  void Create(PU_Info* pu_forest);
136 };
137 
138 
140  : public BaseMap<PUId, PU_Info*>
141 {
142 public:
144  PUIdToPUMap(PU_Info* pu_forest) { Create(pu_forest); }
145  virtual ~PUIdToPUMap() { }
146 
147  void Create(PU_Info* pu_forest);
148 };
149 
150 
151 //***************************************************************************
152 // WNId <-> WN map
153 //***************************************************************************
154 
156  : public BaseMap<WN*, WNId>
157 {
158 public:
160  WNToWNIdMap(WN* wn) { Create(wn); }
161  virtual ~WNToWNIdMap() { }
162 
163  void Create(WN* wn);
164 };
165 
167  : public BaseMap<WNId, WN*>
168 {
169 public:
171  WNIdToWNMap(WN* wn) { Create(wn); }
172  virtual ~WNIdToWNMap() { }
173 
174  void Create(WN* wn);
175 };
176 
177 
178 // ---------------------------------------------------------
179 //
180 // ---------------------------------------------------------
181 
182 // Note: Assumes ownership of the tables it creates
184  : public BaseMap<PU_Info*, WNToWNIdMap*> {
185 
186 public:
188  WNToWNIdTabMap(PU_Info* pu_forest) { Create(pu_forest); }
189  virtual ~WNToWNIdTabMap();
190 
191  void Create(PU_Info* pu_forest);
192  void Destroy();
193 };
194 
196  : public BaseMap<PU_Info*, WNIdToWNMap*> {
197 
198 public:
200  WNIdToWNTabMap(PU_Info* pu_forest) { Create(pu_forest); }
201  virtual ~WNIdToWNTabMap();
202 
203  void Create(PU_Info* pu_forest);
204  void Destroy();
205 };
206 
207 
208 //***************************************************************************
209 // Optional routines for map creation
210 //***************************************************************************
211 
212 // CreateSymTabIdMaps: Given a PU forest, initialize the non-NULL
213 // persistent ID <-> ST_TAB* maps. STTABIds are guaranteed to be
214 // unique within the PU forest 'pu_forest'. (The global symbol table
215 // is included.)
216 void
217 CreateSymTabIdMaps(PU_Info* pu_forest,
218  SymTabToSymTabIdMap* x, SymTabIdToSymTabMap* y);
219 
220 // CreatePUIdMaps: Given a PU forest, initialize the non-NULL
221 // persistent ID <-> PU_Info* maps. PUIds are guaranteed to be unique
222 // within the PU forest 'pu_forest'.
223 void
224 CreatePUIdMaps(PU_Info* pu_forest, PUToPUIdMap* x, PUIdToPUMap* y);
225 
226 // CreateWhirlIDMaps: Given a WN*, initialize the non-NULL persistent
227 // ID <-> WN* maps. WNIds are guaranteed to be unique within the
228 // WHIRL tree rooted at 'wn'. (Note that 'wn' is usually the result of
229 // PU_Info_tree_ptr(PU_Info*).)
230 void
231 CreateWhirlIdMaps(WN* wn, WNToWNIdMap* x, WNIdToWNMap* y);
232 
233 
234 }
235 
236 #endif