[llvm-branch-commits] [llvm-branch] r91093 - in /llvm/branches/Apple/Zoidberg: include/llvm/CodeGen/MachineBasicBlock.h lib/CodeGen/MachineBasicBlock.cpp
Bill Wendling
isanbard at gmail.com
Thu Dec 10 17:50:16 PST 2009
Author: void
Date: Thu Dec 10 19:50:15 2009
New Revision: 91093
URL: http://llvm.org/viewvc/llvm-project?rev=91093&view=rev
Log:
$ svn merge -c 91092 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r91092 into '.':
U include/llvm/CodeGen/MachineBasicBlock.h
U lib/CodeGen/MachineBasicBlock.cpp
Modified:
llvm/branches/Apple/Zoidberg/include/llvm/CodeGen/MachineBasicBlock.h
llvm/branches/Apple/Zoidberg/lib/CodeGen/MachineBasicBlock.cpp
Modified: llvm/branches/Apple/Zoidberg/include/llvm/CodeGen/MachineBasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/include/llvm/CodeGen/MachineBasicBlock.h?rev=91093&r1=91092&r2=91093&view=diff
==============================================================================
--- llvm/branches/Apple/Zoidberg/include/llvm/CodeGen/MachineBasicBlock.h (original)
+++ llvm/branches/Apple/Zoidberg/include/llvm/CodeGen/MachineBasicBlock.h Thu Dec 10 19:50:15 2009
@@ -327,6 +327,11 @@
/// 'Old', change the code and CFG so that it branches to 'New' instead.
void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New);
+ /// BranchesToLandingPad - The basic block branches only to a landing pad or
+ /// to another basic block which branches only to a landing pad. No other
+ /// instructions are present other than the unconditional branch.
+ bool BranchesToLandingPad(const MachineBasicBlock *MBB) const;
+
/// CorrectExtraCFGEdges - Various pieces of code can cause excess edges in
/// the CFG to be inserted. If we have proven that MBB can only branch to
/// DestA and DestB, remove any other MBB successors from the CFG. DestA and
Modified: llvm/branches/Apple/Zoidberg/lib/CodeGen/MachineBasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/lib/CodeGen/MachineBasicBlock.cpp?rev=91093&r1=91092&r2=91093&view=diff
==============================================================================
--- llvm/branches/Apple/Zoidberg/lib/CodeGen/MachineBasicBlock.cpp (original)
+++ llvm/branches/Apple/Zoidberg/lib/CodeGen/MachineBasicBlock.cpp Thu Dec 10 19:50:15 2009
@@ -13,15 +13,16 @@
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/BasicBlock.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Assembly/Writer.h"
#include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetInstrDesc.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Support/LeakDetector.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/Assembly/Writer.h"
#include <algorithm>
using namespace llvm;
@@ -448,10 +449,35 @@
addSuccessor(New);
}
+/// BranchesToLandingPad - The basic block branches only to a landing pad or to
+/// another basic block which branches only to a landing pad. No other
+/// instructions are present other than the unconditional branch.
+bool
+MachineBasicBlock::BranchesToLandingPad(const MachineBasicBlock *MBB) const {
+ SmallSet<const MachineBasicBlock*, 32> Visited;
+ const MachineBasicBlock *CurMBB = MBB;
+
+ while (!Visited.count(CurMBB) && !CurMBB->isLandingPad()) {
+ if (CurMBB->size() != 1 || CurMBB->succ_empty() || CurMBB->succ_size() != 1)
+ break;
+
+ const TargetInstrInfo *TII =
+ CurMBB->getParent()->getTarget().getInstrInfo();
+ if (!TII->isUnpredicatedTerminator(CurMBB->begin()))
+ break;
+
+ Visited.insert(CurMBB);
+ CurMBB = *CurMBB->succ_begin();
+ }
+
+ return CurMBB->isLandingPad();
+}
+
/// CorrectExtraCFGEdges - Various pieces of code can cause excess edges in the
/// CFG to be inserted. If we have proven that MBB can only branch to DestA and
/// DestB, remove any other MBB successors from the CFG. DestA and DestB can
/// be null.
+///
/// Besides DestA and DestB, retain other edges leading to LandingPads
/// (currently there can be only one; we don't check or require that here).
/// Note it is possible that DestA and/or DestB are LandingPads.
@@ -480,16 +506,17 @@
}
MachineBasicBlock::succ_iterator SI = succ_begin();
- MachineBasicBlock *OrigDestA = DestA, *OrigDestB = DestB;
+ const MachineBasicBlock *OrigDestA = DestA, *OrigDestB = DestB;
while (SI != succ_end()) {
- if (*SI == DestA) {
+ const MachineBasicBlock *MBB = *SI;
+ if (MBB == DestA) {
DestA = 0;
++SI;
- } else if (*SI == DestB) {
+ } else if (MBB == DestB) {
DestB = 0;
++SI;
- } else if ((*SI)->isLandingPad() &&
- *SI!=OrigDestA && *SI!=OrigDestB) {
+ } else if (BranchesToLandingPad(MBB) &&
+ MBB != OrigDestA && MBB != OrigDestB) {
++SI;
} else {
// Otherwise, this is a superfluous edge, remove it.
@@ -497,12 +524,14 @@
MadeChange = true;
}
}
+
if (!AddedFallThrough) {
assert(DestA == 0 && DestB == 0 &&
"MachineCFG is missing edges!");
} else if (isCond) {
assert(DestA == 0 && "MachineCFG is missing edges!");
}
+
return MadeChange;
}
More information about the llvm-branch-commits
mailing list