[llvm-commits] [llvm] r103184 - /llvm/trunk/include/llvm/Transforms/Utils/SSAUpdaterImpl.h
Bob Wilson
bob.wilson at apple.com
Thu May 6 09:24:11 PDT 2010
Author: bwilson
Date: Thu May 6 11:24:11 2010
New Revision: 103184
URL: http://llvm.org/viewvc/llvm-project?rev=103184&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/Transforms/Utils/SSAUpdaterImpl.h
Modified: llvm/trunk/include/llvm/Transforms/Utils/SSAUpdaterImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/SSAUpdaterImpl.h?rev=103184&r1=103183&r2=103184&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/SSAUpdaterImpl.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/SSAUpdaterImpl.h Thu May 6 11:24:11 2010
@@ -69,7 +69,7 @@
/// where needed.
ValT GetValue(BlkT *BB) {
SmallVector<BBInfo*, 100> BlockList;
- BuildBlockList(BB, &BlockList);
+ BBInfo *PseudoEntry = BuildBlockList(BB, &BlockList);
// Special case: bail out if BB is unreachable.
if (BlockList.size() == 0) {
@@ -78,7 +78,7 @@
return V;
}
- FindDominators(&BlockList);
+ FindDominators(&BlockList, PseudoEntry);
FindPHIPlacement(&BlockList);
FindAvailableVals(&BlockList);
@@ -89,7 +89,7 @@
/// through its predecessors until reaching blocks with known values.
/// Create BBInfo structures for the blocks and append them to the block
/// list.
- void BuildBlockList(BlkT *BB, BlockListTy *BlockList) {
+ BBInfo *BuildBlockList(BlkT *BB, BlockListTy *BlockList) {
SmallVector<BBInfo*, 10> RootList;
SmallVector<BBInfo*, 64> WorkList;
@@ -106,17 +106,12 @@
Preds.clear();
Traits::FindPredecessorBlocks(Info->BB, &Preds);
Info->NumPreds = Preds.size();
- Info->Preds = static_cast<BBInfo**>
- (Allocator.Allocate(Info->NumPreds * sizeof(BBInfo*),
- AlignOf<BBInfo*>::Alignment));
-
- // Treat an unreachable predecessor as a definition with 'undef'.
- if (Info->NumPreds == 0) {
- Info->AvailableVal = Traits::GetUndefVal(Info->BB, Updater);
- Info->DefBB = Info;
- RootList.push_back(Info);
- continue;
- }
+ if (Info->NumPreds == 0)
+ Info->Preds = 0;
+ else
+ Info->Preds = static_cast<BBInfo**>
+ (Allocator.Allocate(Info->NumPreds * sizeof(BBInfo*),
+ AlignOf<BBInfo*>::Alignment));
for (unsigned p = 0; p != Info->NumPreds; ++p) {
BlkT *Pred = Preds[p];
@@ -187,6 +182,7 @@
}
}
PseudoEntry->BlkNum = BlkNum;
+ return PseudoEntry;
}
/// IntersectDominators - This is the dataflow lattice "meet" operation for
@@ -219,7 +215,7 @@
/// of root nodes for blocks that define the value. The dominators for this
/// subset CFG are not the standard dominators but they are adequate for
/// placing PHIs within the subset CFG.
- void FindDominators(BlockListTy *BlockList) {
+ void FindDominators(BlockListTy *BlockList, BBInfo *PseudoEntry) {
bool Changed;
do {
Changed = false;
@@ -227,19 +223,29 @@
for (typename BlockListTy::reverse_iterator I = BlockList->rbegin(),
E = BlockList->rend(); I != E; ++I) {
BBInfo *Info = *I;
+ BBInfo *NewIDom = 0;
- // Start with the first predecessor.
- assert(Info->NumPreds > 0 && "unreachable block");
- BBInfo *NewIDom = Info->Preds[0];
-
- // Iterate through the block's other predecessors.
- for (unsigned p = 1; p != Info->NumPreds; ++p) {
+ // Iterate through the block's predecessors.
+ for (unsigned p = 0; p != Info->NumPreds; ++p) {
BBInfo *Pred = Info->Preds[p];
- NewIDom = IntersectDominators(NewIDom, Pred);
+
+ // Treat an unreachable predecessor as a definition with 'undef'.
+ if (Pred->BlkNum == 0) {
+ Pred->AvailableVal = Traits::GetUndefVal(Pred->BB, Updater);
+ (*AvailableVals)[Pred->BB] = Pred->AvailableVal;
+ Pred->DefBB = Pred;
+ Pred->BlkNum = PseudoEntry->BlkNum;
+ PseudoEntry->BlkNum++;
+ }
+
+ if (!NewIDom)
+ NewIDom = Pred;
+ else
+ NewIDom = IntersectDominators(NewIDom, Pred);
}
// Check if the IDom value has changed.
- if (NewIDom != Info->IDom) {
+ if (NewIDom && NewIDom != Info->IDom) {
Info->IDom = NewIDom;
Changed = true;
}
More information about the llvm-commits
mailing list