OpenADFortTk (including Open64 and OpenAnalysis references)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ManagerLivenessStandard.cpp
Go to the documentation of this file.
1 
2 // ManagerLivenessStandard.cpp
3 
4 
6 
7 
8 namespace OA {
9  namespace Liveness {
10 
11 static bool debug = false;
12 
13 
17  : mIR(_ir)
18 {
19  OA_DEBUG_CTRL_MACRO("DEBUG_ManagerLivenessStandard:ALL", debug);
21 }
22 
23 OA_ptr<DataFlow::DataFlowSet> ManagerLivenessStandard::initializeTop()
24 {
26  retval = new DataFlow::LocDFSet;
27  return retval;
28 }
29 
30 OA_ptr<DataFlow::DataFlowSet> ManagerLivenessStandard::initializeBottom()
31 {
32  OA_ptr<DataFlow::LocDFSet> retval;
33  retval = new DataFlow::LocDFSet;
34  return retval;
35 }
36 
37 OA_ptr<LivenessStandard> ManagerLivenessStandard::performAnalysis(ProcHandle proc,
40  DataFlow::DFPImplement algorithm)
41 {
42  if (debug) {
43  std::cout << "In Liveness::ManagerLivenessStandard::performAnalysis" << std::endl;
44  }
45  mLiveMap = new LivenessStandard(proc);
46 
47  // store Alias information for use within the transfer function
48  mAlias = alias;
49 
50  // get mapping of statements to locations they may and must define
51  OA_ptr<OA::IRStmtIterator> sIt = mIR->getStmtIterator(proc);
52  for ( ; sIt->isValid(); (*sIt)++) {
53  OA::StmtHandle stmt = sIt->current();
54  if (debug) {
55  std::cout<< "\tstmt (" << stmt.hval() << ") = ";
56  mIR->dump(stmt,std::cout);
57  }
58 
59  // initialize each stmt to define an empty set of locations
60  mStmtMustDefMap[stmt];
61  mStmtMayUseMap[stmt];
62 
63  // locations that each statement may or must def
64  OA_ptr<MemRefHandleIterator> defIterPtr = mIR->getDefMemRefs(stmt);
65  for (; defIterPtr->isValid(); (*defIterPtr)++) {
66  MemRefHandle ref = defIterPtr->current();
67  if (debug) {
68  std::cout << "\t\tdef ref (" << ref.hval() << ") = ";
69  mIR->dump(ref,std::cout);
70  }
71 
72  OA_ptr<LocIterator> locIterPtr = alias->getMustLocs(ref);
73  for (; locIterPtr->isValid(); ++(*locIterPtr)) {
74  mStmtMustDefMap[stmt].insert(locIterPtr->current());
75  }
76 
77  }
78 
79  // must or may defines from procedure calls
80  OA_ptr<IRCallsiteIterator> callsiteItPtr = mIR->getCallsites(stmt);
81  for ( ; callsiteItPtr->isValid(); ++(*callsiteItPtr)) {
82  CallHandle expr = callsiteItPtr->current();
83 
84  OA_ptr<LocIterator> locIterPtr;
85 
86  // DEF
87  locIterPtr = interSE->getDEFIterator(expr);
88  for ( ; locIterPtr->isValid(); (*locIterPtr)++) {
89  OA_ptr<Location> defLocPtr = locIterPtr->current();
90  mStmtMustDefMap[stmt].insert(defLocPtr);
91  }
92  }
93 
94 
95  OA_ptr<MemRefHandleIterator> useIterPtr = mIR->getUseMemRefs(stmt);
96  for (; useIterPtr->isValid(); (*useIterPtr)++) {
97  MemRefHandle useref = useIterPtr->current();
98  if (debug) {
99  std::cout << "\t\tuse ref (" << useref.hval() << ") = ";
100  mIR->dump(useref,std::cout);
101  }
102 
103  OA_ptr<LocIterator> uselocIterPtr = alias->getMayLocs(useref);
104  for (; uselocIterPtr->isValid(); ++(*uselocIterPtr)) {
105  mStmtMayUseMap[stmt].insert(uselocIterPtr->current());
106  }
107 
108  }
109 
110 
111  }//loop over statements
112 
113  // use the dataflow solver to get the In and Out sets for the BBs
114  //DataFlow::CFGDFProblem::solve(cfg);
115  //
116 
117  mSolver->solve(cfg,algorithm);
118 
119  // get exit node for CFG and determine what definitions reach that node
121 
122  node = cfg->getExit();
123 
124  OA_ptr<DataFlow::DataFlowSet> x = mSolver->getOutSet(node);
125 
127  = x.convert<DataFlow::LocDFSet >();
128 
129 
130  return mLiveMap;
131 
132 }
133 
135 ManagerLivenessStandard::initializeNodeIN(OA_ptr<CFG::NodeInterface> n)
136 {
138  retval = new DataFlow::LocDFSet;
139  return retval;
140 }
141 
143 ManagerLivenessStandard::initializeNodeOUT(OA_ptr<CFG::NodeInterface> n)
144 {
146  retval = new DataFlow::LocDFSet;
147  return retval;
148 }
149 
150 
151 
152 OA_ptr<DataFlow::DataFlowSet>
153 ManagerLivenessStandard::meet (OA_ptr<DataFlow::DataFlowSet> set1orig,
154  OA_ptr<DataFlow::DataFlowSet> set2orig)
155 {
156  OA_ptr<DataFlow::LocDFSet> set1
157  = set1orig.convert<DataFlow::LocDFSet>();
158  if (debug) {
159  std::cout << "ManagerLivenessStandard::meet" << std::endl;
160  std::cout << "\tset1 = ";
161  set1->dump(std::cout,mIR);
162  std::cout << ", set2 = ";
163  set2orig->dump(std::cout,mIR);
164  }
165 
166  DataFlow::LocDFSet retval
167  = set1->setUnion(*set2orig);
168  if (debug) {
169  std::cout << std::endl << "\tretval set = ";
170  retval.dump(std::cout,mIR);
171  std::cout << std::endl;
172  }
173 
174  return retval.clone();
175 }
176 
177 
178 OA_ptr<DataFlow::DataFlowSet>
179 ManagerLivenessStandard::transfer(OA_ptr<DataFlow::DataFlowSet> in, OA::StmtHandle stmt)
180 {
181  OA_ptr<DataFlow::LocDFSet> inRecast
182  = in.convert<DataFlow::LocDFSet>();
183 
184  if (debug) {
185  std::cout << "In transfer, stmt(hval=" << stmt.hval() << ")= ";
186  mIR->dump(stmt,std::cout);
187  }
188 
189 
190  DataFlow::LocDFSetIterator inIter(*inRecast);
191  for (; inIter.isValid(); ++inIter) {
192  OA_ptr<Location> livevar = inIter.current();
193  if (debug) {
194  std::cout << "\tlivevar in Inset = ";
195  livevar->dump(std::cout,mIR);
196  }
197 
198  mLiveMap->insertLive(stmt,livevar);
199  }
200  LocSet::iterator setIter;
201  for (setIter=mStmtMustDefMap[stmt].begin(); setIter!=mStmtMustDefMap[stmt].end(); setIter++) {
202  OA_ptr<Location> loc = *setIter;
203  inRecast->remove(loc);
204  mLiveMap->removeLive(stmt,loc);
205 
206  }
207 
208  LocSet::iterator gensetIter;
209  for (gensetIter=mStmtMayUseMap[stmt].begin(); gensetIter!=mStmtMayUseMap[stmt].end(); gensetIter++) {
210  OA_ptr<Location> loc = *gensetIter;
211  inRecast->insert(loc);
212  mLiveMap->insertLive(stmt,loc);
213 
214  }
215 
216  return inRecast;
217  }
218 
219  } // end of namespace Liveness
220 } // end of namespace OA