Reapply 68073, with fixes. EH Landing-pad basic blocks are not
authorDan Gohman <gohman@apple.com>
Tue, 31 Mar 2009 18:39:13 +0000 (18:39 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 31 Mar 2009 18:39:13 +0000 (18:39 +0000)
entered via fall-through. Don't miss fallthroughs from blocks
terminated by conditional branches. Also, move
isOnlyReachableByFallthrough out of line.

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

include/llvm/CodeGen/MachineBasicBlock.h
lib/CodeGen/MachineBasicBlock.cpp
lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp

index 1ba7e798f832d602f5686a2f8b08ce6322fa3198..134d22663b01dfb7925830596cc38408f335b913 100644 (file)
@@ -253,6 +253,11 @@ public:
   /// it returns end()
   iterator getFirstTerminator();
 
+  /// isOnlyReachableViaFallthough - Return true if this basic block has
+  /// exactly one predecessor and the control transfer mechanism between
+  /// the predecessor and this block is a fall-through.
+  bool isOnlyReachableByFallthrough() const;
+
   void pop_front() { Insts.pop_front(); }
   void pop_back() { Insts.pop_back(); }
   void push_back(MachineInstr *MI) { Insts.push_back(MI); }
index 51f0f9d0001f02ff0b727041e826edd7a9ea20b3..5ac54ea8a44389b0f74a005e1cf47b2638093f6e 100644 (file)
@@ -123,6 +123,16 @@ MachineBasicBlock::iterator MachineBasicBlock::getFirstTerminator() {
   return I;
 }
 
+bool
+MachineBasicBlock::isOnlyReachableByFallthrough() const {
+  return !isLandingPad() &&
+         !pred_empty() &&
+         next(pred_begin()) == pred_end() &&
+         (*pred_begin())->isLayoutSuccessor(this) &&
+         ((*pred_begin())->empty() ||
+          !(*pred_begin())->back().getDesc().isBarrier());
+}
+
 void MachineBasicBlock::dump() const {
   print(*cerr.stream());
 }
index 3bdcf88365f9bde8a67edca807ee6f879e4b3352..3b6b0efec5af0009d50528444fd57ef69f29a6ac 100644 (file)
@@ -238,7 +238,10 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
        I != E; ++I) {
     // Print a label for the basic block.
-    if (!I->pred_empty()) {
+    if (!VerboseAsm && (I->pred_empty() || I->isOnlyReachableByFallthrough())) {
+      // This is an entry block or a block that's only reachable via a
+      // fallthrough edge. In non-VerboseAsm mode, don't print the label.
+    } else {
       printBasicBlockLabel(I, true, true, VerboseAsm);
       O << '\n';
     }