llvm.org GIT mirror llvm / c52edc7
Fix handling of unreachable blocks in the SSAUpdater. The previous code only handled cases where a block had zero predecessors, but failed to detect other cases like loops with no entries. The SSAUpdater is already doing a forward traversal through the blocks, so it is not hard to identify the blocks that were never reached on that traversal. This fixes the crash for ppc on the stepanov_vector test. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103184 91177308-0d34-0410-b5e6-96231b3b80d8 Bob Wilson 10 years ago
1 changed file(s) with 30 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
6868 /// where needed.
6969 ValT GetValue(BlkT *BB) {
7070 SmallVector BlockList;
71 BuildBlockList(BB, &BlockList);
71 BBInfo *PseudoEntry = BuildBlockList(BB, &BlockList);
7272
7373 // Special case: bail out if BB is unreachable.
7474 if (BlockList.size() == 0) {
7777 return V;
7878 }
7979
80 FindDominators(&BlockList);
80 FindDominators(&BlockList, PseudoEntry);
8181 FindPHIPlacement(&BlockList);
8282 FindAvailableVals(&BlockList);
8383
8888 /// through its predecessors until reaching blocks with known values.
8989 /// Create BBInfo structures for the blocks and append them to the block
9090 /// list.
91 void BuildBlockList(BlkT *BB, BlockListTy *BlockList) {
91 BBInfo *BuildBlockList(BlkT *BB, BlockListTy *BlockList) {
9292 SmallVector RootList;
9393 SmallVector WorkList;
9494
105105 Preds.clear();
106106 Traits::FindPredecessorBlocks(Info->BB, &Preds);
107107 Info->NumPreds = Preds.size();
108 Info->Preds = static_cast
109 (Allocator.Allocate(Info->NumPreds * sizeof(BBInfo*),
110 AlignOf::Alignment));
111
112 // Treat an unreachable predecessor as a definition with 'undef'.
113 if (Info->NumPreds == 0) {
114 Info->AvailableVal = Traits::GetUndefVal(Info->BB, Updater);
115 Info->DefBB = Info;
116 RootList.push_back(Info);
117 continue;
118 }
108 if (Info->NumPreds == 0)
109 Info->Preds = 0;
110 else
111 Info->Preds = static_cast
112 (Allocator.Allocate(Info->NumPreds * sizeof(BBInfo*),
113 AlignOf::Alignment));
119114
120115 for (unsigned p = 0; p != Info->NumPreds; ++p) {
121116 BlkT *Pred = Preds[p];
186181 }
187182 }
188183 PseudoEntry->BlkNum = BlkNum;
184 return PseudoEntry;
189185 }
190186
191187 /// IntersectDominators - This is the dataflow lattice "meet" operation for
218214 /// of root nodes for blocks that define the value. The dominators for this
219215 /// subset CFG are not the standard dominators but they are adequate for
220216 /// placing PHIs within the subset CFG.
221 void FindDominators(BlockListTy *BlockList) {
217 void FindDominators(BlockListTy *BlockList, BBInfo *PseudoEntry) {
222218 bool Changed;
223219 do {
224220 Changed = false;
226222 for (typename BlockListTy::reverse_iterator I = BlockList->rbegin(),
227223 E = BlockList->rend(); I != E; ++I) {
228224 BBInfo *Info = *I;
229
230 // Start with the first predecessor.
231 assert(Info->NumPreds > 0 && "unreachable block");
232 BBInfo *NewIDom = Info->Preds[0];
233
234 // Iterate through the block's other predecessors.
235 for (unsigned p = 1; p != Info->NumPreds; ++p) {
225 BBInfo *NewIDom = 0;
226
227 // Iterate through the block's predecessors.
228 for (unsigned p = 0; p != Info->NumPreds; ++p) {
236229 BBInfo *Pred = Info->Preds[p];
237 NewIDom = IntersectDominators(NewIDom, Pred);
230
231 // Treat an unreachable predecessor as a definition with 'undef'.
232 if (Pred->BlkNum == 0) {
233 Pred->AvailableVal = Traits::GetUndefVal(Pred->BB, Updater);
234 (*AvailableVals)[Pred->BB] = Pred->AvailableVal;
235 Pred->DefBB = Pred;
236 Pred->BlkNum = PseudoEntry->BlkNum;
237 PseudoEntry->BlkNum++;
238 }
239
240 if (!NewIDom)
241 NewIDom = Pred;
242 else
243 NewIDom = IntersectDominators(NewIDom, Pred);
238244 }
239245
240246 // Check if the IDom value has changed.
241 if (NewIDom != Info->IDom) {
247 if (NewIDom && NewIDom != Info->IDom) {
242248 Info->IDom = NewIDom;
243249 Changed = true;
244250 }