Add a new MachineBasicBlock utility function, isLayoutSuccessor, that
authorDan Gohman <gohman@apple.com>
Thu, 2 Oct 2008 22:09:09 +0000 (22:09 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 2 Oct 2008 22:09:09 +0000 (22:09 +0000)
can be used when deciding if a block can transfer control to another
via a fall-through instead of a branch.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56968 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineBasicBlock.h
lib/CodeGen/MachineBasicBlock.cpp

index b47108a862701a866d0c2d0e03181f007d80b3f3..09cca93e2ff8cdfdfe13d5ead239d71b59c2620f 100644 (file)
@@ -234,6 +234,13 @@ public:
   /// block.
   bool isSuccessor(MachineBasicBlock *MBB) const;
 
+  /// isLayoutSuccessor - Return true if the specified MBB will be emitted
+  /// immediately after this block, such that if this block exits by
+  /// falling through, control will transfer to the specified MBB. Note
+  /// that MBB need not be a successor at all, for example if this block
+  /// ends with an unconditional branch to some other block.
+  bool isLayoutSuccessor(MachineBasicBlock *MBB) const;
+
   /// getFirstTerminator - returns an iterator to the first terminator
   /// instruction of this basic block. If a terminator does not exist,
   /// it returns end()
index 0320affa3a557ffb6a752da0df0eea0e29bce28e..bac0a6cc7196d296298f8bc851d9e4da56a29db5 100644 (file)
@@ -254,6 +254,11 @@ bool MachineBasicBlock::isSuccessor(MachineBasicBlock *MBB) const {
   return I != Successors.end();
 }
 
+bool MachineBasicBlock::isLayoutSuccessor(MachineBasicBlock *MBB) const {
+  MachineFunction::const_iterator I(this);
+  return next(I) == MachineFunction::const_iterator(MBB);
+}
+
 /// removeFromParent - This method unlinks 'this' from the containing function,
 /// and returns it, but does not delete it.
 MachineBasicBlock *MachineBasicBlock::removeFromParent() {