Reapply r100056. It doesn't look like it's the one that's causing a failure.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100065 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling
2010-04-01 00:00:43 +00:00
parent 62d1da0bb9
commit e543d161a0

View File

@ -23,6 +23,7 @@
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Assembly/Writer.h" #include "llvm/Assembly/Writer.h"
#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/LeakDetector.h" #include "llvm/Support/LeakDetector.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
@ -459,54 +460,41 @@ bool MachineBasicBlock::CorrectExtraCFGEdges(MachineBasicBlock *DestA,
// conditional branch followed by an unconditional branch. DestA is the // conditional branch followed by an unconditional branch. DestA is the
// 'true' destination and DestB is the 'false' destination. // 'true' destination and DestB is the 'false' destination.
bool MadeChange = false; bool Changed = false;
bool AddedFallThrough = false;
MachineFunction::iterator FallThru = MachineFunction::iterator FallThru =
llvm::next(MachineFunction::iterator(this)); llvm::next(MachineFunction::iterator(this));
if (isCond) { if (DestA == 0 && DestB == 0) {
// If this block ends with a conditional branch that falls through to its // Block falls through to successor.
// successor, set DestB as the successor. DestA = FallThru;
if (DestB == 0 && FallThru != getParent()->end()) { DestB = FallThru;
} else if (DestA != 0 && DestB == 0) {
if (isCond)
// Block ends in conditional jump that falls through to successor.
DestB = FallThru; DestB = FallThru;
AddedFallThrough = true;
}
} else { } else {
// If this is an unconditional branch with no explicit dest, it must just be assert(DestA && DestB && isCond &&
// a fallthrough into DestA. "CFG in a bad state. Cannot correct CFG edges");
if (DestA == 0 && FallThru != getParent()->end()) {
DestA = FallThru;
AddedFallThrough = true;
}
} }
// Remove superfluous edges. I.e., those which aren't destinations of this
// basic block, duplicate edges, or landing pads.
SmallPtrSet<const MachineBasicBlock*, 8> SeenMBBs;
MachineBasicBlock::succ_iterator SI = succ_begin(); MachineBasicBlock::succ_iterator SI = succ_begin();
MachineBasicBlock *OrigDestA = DestA, *OrigDestB = DestB;
while (SI != succ_end()) { while (SI != succ_end()) {
const MachineBasicBlock *MBB = *SI; const MachineBasicBlock *MBB = *SI;
if (MBB == DestA) { if (!SeenMBBs.insert(MBB) ||
DestA = 0; (MBB != DestA && MBB != DestB && !MBB->isLandingPad())) {
++SI; // This is a superfluous edge, remove it.
} else if (MBB == DestB) {
DestB = 0;
++SI;
} else if (MBB->isLandingPad() &&
MBB != OrigDestA && MBB != OrigDestB) {
++SI;
} else {
// Otherwise, this is a superfluous edge, remove it.
SI = removeSuccessor(SI); SI = removeSuccessor(SI);
MadeChange = true; Changed = true;
} else {
++SI;
} }
} }
if (!AddedFallThrough) return Changed;
assert(DestA == 0 && DestB == 0 && "MachineCFG is missing edges!");
else if (isCond)
assert(DestA == 0 && "MachineCFG is missing edges!");
return MadeChange;
} }
/// findDebugLoc - find the next valid DebugLoc starting at MBBI, skipping /// findDebugLoc - find the next valid DebugLoc starting at MBBI, skipping