summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MachineBasicBlock.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2010-03-31 23:26:26 +0000
committerBill Wendling <isanbard@gmail.com>2010-03-31 23:26:26 +0000
commitfa9810de3b8e639fecb0924a4f0a2ed687f303b3 (patch)
treec161e613e2e8ccf6bfba62b3740aaf4063fb2b81 /llvm/lib/CodeGen/MachineBasicBlock.cpp
parentf5af3584cab155ba4da7957a018098b3765b4641 (diff)
downloadbcm5719-llvm-fa9810de3b8e639fecb0924a4f0a2ed687f303b3.tar.gz
bcm5719-llvm-fa9810de3b8e639fecb0924a4f0a2ed687f303b3.zip
Revert r100056. It was causing a failure on MSVC.
llvm-svn: 100062
Diffstat (limited to 'llvm/lib/CodeGen/MachineBasicBlock.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineBasicBlock.cpp58
1 files changed, 35 insertions, 23 deletions
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index bd0ccb40f53..fbe4fc2f46f 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -23,7 +23,6 @@
#include "llvm/Target/TargetMachine.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/LeakDetector.h"
#include "llvm/Support/raw_ostream.h"
@@ -460,41 +459,54 @@ bool MachineBasicBlock::CorrectExtraCFGEdges(MachineBasicBlock *DestA,
// conditional branch followed by an unconditional branch. DestA is the
// 'true' destination and DestB is the 'false' destination.
- bool Changed = false;
+ bool MadeChange = false;
+ bool AddedFallThrough = false;
MachineFunction::iterator FallThru =
llvm::next(MachineFunction::iterator(this));
-
- if (DestA == 0 && DestB == 0) {
- // Block falls through to successor.
- DestA = FallThru;
- DestB = FallThru;
- } else if (DestA != 0 && DestB == 0) {
- if (isCond)
- // Block ends in conditional jump that falls through to successor.
+
+ if (isCond) {
+ // If this block ends with a conditional branch that falls through to its
+ // successor, set DestB as the successor.
+ if (DestB == 0 && FallThru != getParent()->end()) {
DestB = FallThru;
+ AddedFallThrough = true;
+ }
} else {
- assert(DestA && DestB && isCond &&
- "CFG in a bad state. Cannot correct CFG edges");
+ // If this is an unconditional branch with no explicit dest, it must just be
+ // a fallthrough into DestA.
+ 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 *OrigDestA = DestA, *OrigDestB = DestB;
while (SI != succ_end()) {
const MachineBasicBlock *MBB = *SI;
- if (!SeenMBBs.insert(MBB) ||
- (MBB != DestA && MBB != DestB && !MBB->isLandingPad())) {
- // This is a superfluous edge, remove it.
- SI = removeSuccessor(SI);
- Changed = true;
- } else {
+ if (MBB == DestA) {
+ DestA = 0;
+ ++SI;
+ } 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);
+ MadeChange = true;
}
}
- return Changed;
+ if (!AddedFallThrough)
+ 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
OpenPOWER on IntegriCloud