llvm.org GIT mirror llvm / cd4abb7
Remove DomSet completely. This concludes work on PR1171. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35775 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 12 years ago
6 changed file(s) with 6 addition(s) and 252 deletion(s). Raw diff Collapse all Expand all
99 // This file defines the following classes:
1010 // 1. ImmediateDominators: Calculates and holds a mapping between BasicBlocks
1111 // and their immediate dominator.
12 // 2. DominatorSet: Calculates the [reverse] dominator set for a function
13 // 3. DominatorTree: Represent the ImmediateDominator as an explicit tree
12 // 2. DominatorTree: Represent the ImmediateDominator as an explicit tree
1413 // structure.
15 // 4. ETForest: Efficient data structure for dominance comparisons and
14 // 3. ETForest: Efficient data structure for dominance comparisons and
1615 // nearest-common-ancestor queries.
17 // 5. DominanceFrontier: Calculate and hold the dominance frontier for a
16 // 4. DominanceFrontier: Calculate and hold the dominance frontier for a
1817 // function.
1918 //
2019 // These data structures are listed in increasing order of complexity. It
172171 void Compress(BasicBlock *V, InfoRec &VInfo);
173172 BasicBlock *Eval(BasicBlock *v);
174173 void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
175 };
176
177
178
179 //===----------------------------------------------------------------------===//
180 /// DominatorSet - Maintain a set for every basic block in a
181 /// function, that represents the blocks that dominate the block. If the block
182 /// is unreachable in this function, the set will be empty. This cannot happen
183 /// for reachable code, because every block dominates at least itself.
184 ///
185 class DominatorSetBase : public DominatorBase {
186 public:
187 typedef std::set DomSetType; // Dom set for a bb
188 // Map of dom sets
189 typedef std::map DomSetMapType;
190 protected:
191 DomSetMapType Doms;
192 public:
193 DominatorSetBase(bool isPostDom) : DominatorBase(isPostDom) {}
194
195 virtual void releaseMemory() { Doms.clear(); }
196
197 // Accessor interface:
198 typedef DomSetMapType::const_iterator const_iterator;
199 typedef DomSetMapType::iterator iterator;
200 inline const_iterator begin() const { return Doms.begin(); }
201 inline iterator begin() { return Doms.begin(); }
202 inline const_iterator end() const { return Doms.end(); }
203 inline iterator end() { return Doms.end(); }
204 inline const_iterator find(BasicBlock* B) const { return Doms.find(B); }
205 inline iterator find(BasicBlock* B) { return Doms.find(B); }
206
207
208 /// getDominators - Return the set of basic blocks that dominate the specified
209 /// block.
210 ///
211 inline const DomSetType &getDominators(BasicBlock *BB) const {
212 const_iterator I = find(BB);
213 assert(I != end() && "BB not in function!");
214 return I->second;
215 }
216
217 /// isReachable - Return true if the specified basicblock is reachable. If
218 /// the block is reachable, we have dominator set information for it.
219 ///
220 bool isReachable(BasicBlock *BB) const {
221 return !getDominators(BB).empty();
222 }
223
224 /// dominates - Return true if A dominates B.
225 ///
226 inline bool dominates(BasicBlock *A, BasicBlock *B) const {
227 return getDominators(B).count(A) != 0;
228 }
229
230 /// properlyDominates - Return true if A dominates B and A != B.
231 ///
232 bool properlyDominates(BasicBlock *A, BasicBlock *B) const {
233 return dominates(A, B) && A != B;
234 }
235
236 /// print - Convert to human readable form
237 ///
238 virtual void print(std::ostream &OS, const Module* = 0) const;
239 void print(std::ostream *OS, const Module* M = 0) const {
240 if (OS) print(*OS, M);
241 }
242
243 /// dominates - Return true if A dominates B. This performs the special
244 /// checks necessary if A and B are in the same basic block.
245 ///
246 bool dominates(Instruction *A, Instruction *B) const;
247
248 //===--------------------------------------------------------------------===//
249 // API to update (Post)DominatorSet information based on modifications to
250 // the CFG...
251
252 /// addBasicBlock - Call to update the dominator set with information about a
253 /// new block that was inserted into the function.
254 ///
255 void addBasicBlock(BasicBlock *BB, const DomSetType &Dominators) {
256 assert(find(BB) == end() && "Block already in DominatorSet!");
257 Doms.insert(std::make_pair(BB, Dominators));
258 }
259
260 /// addDominator - If a new block is inserted into the CFG, then method may be
261 /// called to notify the blocks it dominates that it is in their set.
262 ///
263 void addDominator(BasicBlock *BB, BasicBlock *NewDominator) {
264 iterator I = find(BB);
265 assert(I != end() && "BB is not in DominatorSet!");
266 I->second.insert(NewDominator);
267 }
268 };
269
270
271 //===-------------------------------------
272 /// DominatorSet Class - Concrete subclass of DominatorSetBase that is used to
273 /// compute a normal dominator set.
274 ///
275 class DominatorSet : public DominatorSetBase {
276 public:
277 DominatorSet() : DominatorSetBase(false) {}
278
279 virtual bool runOnFunction(Function &F);
280
281 BasicBlock *getRoot() const {
282 assert(Roots.size() == 1 && "Should always have entry node!");
283 return Roots[0];
284 }
285
286 /// getAnalysisUsage - This simply provides a dominator set
287 ///
288 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
289 AU.addRequired();
290 AU.setPreservesAll();
291 }
292
293 // stub - dummy function, just ignore it
294 static int stub;
295174 };
296175
297176
690569
691570 } // End llvm namespace
692571
693 // Make sure that any clients of this file link in Dominators.cpp
694 FORCE_DEFINING_FILE_TO_BE_LINKED(DominatorSet)
695
696572 #endif
250250 o << "\n";
251251 }
252252
253
254
255 //===----------------------------------------------------------------------===//
256 // DominatorSet Implementation
257 //===----------------------------------------------------------------------===//
258
259 static RegisterPass
260 B("domset", "Dominator Set Construction", true);
261
262 // dominates - Return true if A dominates B. This performs the special checks
263 // necessary if A and B are in the same basic block.
264 //
265 bool DominatorSetBase::dominates(Instruction *A, Instruction *B) const {
266 BasicBlock *BBA = A->getParent(), *BBB = B->getParent();
267 if (BBA != BBB) return dominates(BBA, BBB);
268
269 // It is not possible to determine dominance between two PHI nodes
270 // based on their ordering.
271 if (isa(A) && isa(B))
272 return false;
273
274 // Loop through the basic block until we find A or B.
275 BasicBlock::iterator I = BBA->begin();
276 for (; &*I != A && &*I != B; ++I) /*empty*/;
277
278 if(!IsPostDominators) {
279 // A dominates B if it is found first in the basic block.
280 return &*I == A;
281 } else {
282 // A post-dominates B if B is found first in the basic block.
283 return &*I == B;
284 }
285 }
286
287
288 // runOnFunction - This method calculates the forward dominator sets for the
289 // specified function.
290 //
291 bool DominatorSet::runOnFunction(Function &F) {
292 BasicBlock *Root = &F.getEntryBlock();
293 Roots.clear();
294 Roots.push_back(Root);
295 assert(pred_begin(Root) == pred_end(Root) &&
296 "Root node has predecessors in function!");
297
298 ImmediateDominators &ID = getAnalysis();
299 Doms.clear();
300 if (Roots.empty()) return false;
301
302 // Root nodes only dominate themselves.
303 for (unsigned i = 0, e = Roots.size(); i != e; ++i)
304 Doms[Roots[i]].insert(Roots[i]);
305
306 // Loop over all of the blocks in the function, calculating dominator sets for
307 // each function.
308 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
309 if (BasicBlock *IDom = ID[I]) { // Get idom if block is reachable
310 DomSetType &DS = Doms[I];
311 assert(DS.empty() && "Domset already filled in for this block?");
312 DS.insert(I); // Blocks always dominate themselves
313
314 // Insert all dominators into the set...
315 while (IDom) {
316 // If we have already computed the dominator sets for our immediate
317 // dominator, just use it instead of walking all the way up to the root.
318 DomSetType &IDS = Doms[IDom];
319 if (!IDS.empty()) {
320 DS.insert(IDS.begin(), IDS.end());
321 break;
322 } else {
323 DS.insert(IDom);
324 IDom = ID[IDom];
325 }
326 }
327 } else {
328 // Ensure that every basic block has at least an empty set of nodes. This
329 // is important for the case when there is unreachable blocks.
330 Doms[I];
331 }
332
333 return false;
334 }
335
336253 namespace llvm {
337254 static std::ostream &operator<<(std::ostream &o,
338255 const std::set &BBs) {
344261 o << " <>";
345262 return o;
346263 }
347 }
348
349 void DominatorSetBase::print(std::ostream &o, const Module* ) const {
350 for (const_iterator I = begin(), E = end(); I != E; ++I) {
351 o << " DomSet For BB: ";
352 if (I->first)
353 WriteAsOperand(o, I->first, false);
354 else
355 o << " <>";
356 o << " is:\t" << I->second << "\n";
357 }
358264 }
359265
360266 //===----------------------------------------------------------------------===//
1071977 }
1072978 o << "\n";
1073979 }
1074
1075 DEFINING_FILE_FOR(DominatorSet)
+0
-15
test/Analysis/Dominators/2003-05-12-UnreachableCode.ll less more
None ; RUN: llvm-upgrade < %s | llvm-as | opt -analyze -domset -disable-verify
1 ;
2 int %re_match_2() {
3 ENTRY:
4 br label %loopexit.20
5 loopentry.20:
6 br label %loopexit.20
7
8 loopexit.20:
9 ret int 0
10
11 endif.46: ; UNREACHABLE
12 br label %loopentry.20
13
14 }
None ; RUN: llvm-as < %s | opt -domset -break-crit-edges -domtree -disable-output
0 ; RUN: llvm-as < %s | opt -break-crit-edges -domtree -disable-output
11 ; PR1110
22
33 %struct.OggVorbis_File = type { i8*, i32, i64, i64, %struct.ogg_sync_state, i32, i64*, i64*, i32*, i64*, %struct.vorbis_info*, %struct.vorbis_comment*, i64, i32, i32, i32, double, double, %struct.ogg_stream_state, %struct.vorbis_dsp_state, %struct.vorbis_block, %struct.ov_callbacks }
0 ; Basic test for bugpoint.
1 ; RUN: bugpoint %s -domset -idom -domset -bugpoint-crashcalls \
2 ; RUN: -domset -idom -domset
1 ; RUN: bugpoint %s -idom -bugpoint-crashcalls \
2 ; RUN: -idom
33
44 define i32 @test() {
55 call i32 @test()
+0
-11
test/Other/2002-08-02-DomSetProblem.ll less more
None ; Dominator set calculation is not calculating dominators for unreachable
1 ; blocks. These blocks should at least dominate themselves. This is
2 ; fouling up the verify pass.
3 ;
4 ; RUN: llvm-upgrade < %s | llvm-as | opt -analyze -domset | grep BB
5
6 void %test() {
7 ret void
8 BB:
9 ret void
10 }