1263320SdimPull in r199061 from upstream llvm trunk (by Jakob Stoklund Olesen):
2263320Sdim
3263320Sdim  Handle bundled terminators in isBlockOnlyReachableByFallthrough.
4263320Sdim
5263320Sdim  Targets like SPARC and MIPS have delay slots and normally bundle the
6263320Sdim  delay slot instruction with the corresponding terminator.
7263320Sdim
8263320Sdim  Teach isBlockOnlyReachableByFallthrough to find any MBB operands on
9263320Sdim  bundled terminators so SPARC doesn't need to specialize this function.
10263320Sdim
11263320SdimIntroduced here: http://svn.freebsd.org/changeset/base/262261
12263320Sdim
13263320SdimIndex: test/CodeGen/SPARC/missinglabel.ll
14263320Sdim===================================================================
15263320Sdim--- test/CodeGen/SPARC/missinglabel.ll
16263320Sdim+++ test/CodeGen/SPARC/missinglabel.ll
17263320Sdim@@ -0,0 +1,23 @@
18263320Sdim+; RUN: llc < %s -verify-machineinstrs | FileCheck %s
19263320Sdim+target datalayout = "E-m:e-i64:64-n32:64-S128"
20263320Sdim+target triple = "sparc64-unknown-linux-gnu"
21263320Sdim+
22263320Sdim+define void @f() align 2 {
23263320Sdim+entry:
24263320Sdim+; CHECK: %xcc, .LBB0_1
25263320Sdim+  %cmp = icmp eq i64 undef, 0
26263320Sdim+  br i1 %cmp, label %targetblock, label %cond.false
27263320Sdim+
28263320Sdim+cond.false:
29263320Sdim+  unreachable
30263320Sdim+
31263320Sdim+; CHECK: .LBB0_1: ! %targetblock
32263320Sdim+targetblock:
33263320Sdim+  br i1 undef, label %cond.false.i83, label %exit.i85
34263320Sdim+
35263320Sdim+cond.false.i83:
36263320Sdim+  unreachable
37263320Sdim+
38263320Sdim+exit.i85:
39263320Sdim+  unreachable
40263320Sdim+}
41263320SdimIndex: lib/Target/Sparc/SparcAsmPrinter.cpp
42263320Sdim===================================================================
43263320Sdim--- lib/Target/Sparc/SparcAsmPrinter.cpp
44263320Sdim+++ lib/Target/Sparc/SparcAsmPrinter.cpp
45263320Sdim@@ -65,10 +65,6 @@ namespace {
46263320Sdim     bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
47263320Sdim                                unsigned AsmVariant, const char *ExtraCode,
48263320Sdim                                raw_ostream &O);
49263320Sdim-
50263320Sdim-    virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB)
51263320Sdim-                       const;
52263320Sdim-
53263320Sdim   };
54263320Sdim } // end of anonymous namespace
55263320Sdim 
56263320Sdim@@ -390,37 +386,6 @@ bool SparcAsmPrinter::PrintAsmMemoryOperand(const
57263320Sdim   return false;
58263320Sdim }
59263320Sdim 
60263320Sdim-/// isBlockOnlyReachableByFallthough - Return true if the basic block has
61263320Sdim-/// exactly one predecessor and the control transfer mechanism between
62263320Sdim-/// the predecessor and this block is a fall-through.
63263320Sdim-///
64263320Sdim-/// This overrides AsmPrinter's implementation to handle delay slots.
65263320Sdim-bool SparcAsmPrinter::
66263320Sdim-isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const {
67263320Sdim-  // If this is a landing pad, it isn't a fall through.  If it has no preds,
68263320Sdim-  // then nothing falls through to it.
69263320Sdim-  if (MBB->isLandingPad() || MBB->pred_empty())
70263320Sdim-    return false;
71263320Sdim-
72263320Sdim-  // If there isn't exactly one predecessor, it can't be a fall through.
73263320Sdim-  MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(), PI2 = PI;
74263320Sdim-  ++PI2;
75263320Sdim-  if (PI2 != MBB->pred_end())
76263320Sdim-    return false;
77263320Sdim-
78263320Sdim-  // The predecessor has to be immediately before this block.
79263320Sdim-  const MachineBasicBlock *Pred = *PI;
80263320Sdim-
81263320Sdim-  if (!Pred->isLayoutSuccessor(MBB))
82263320Sdim-    return false;
83263320Sdim-
84263320Sdim-  // Check if the last terminator is an unconditional branch.
85263320Sdim-  MachineBasicBlock::const_iterator I = Pred->end();
86263320Sdim-  while (I != Pred->begin() && !(--I)->isTerminator())
87263320Sdim-    ; // Noop
88263320Sdim-  return I == Pred->end() || !I->isBarrier();
89263320Sdim-}
90263320Sdim-
91263320Sdim // Force static initialization.
92263320Sdim extern "C" void LLVMInitializeSparcAsmPrinter() {
93263320Sdim   RegisterAsmPrinter<SparcAsmPrinter> X(TheSparcTarget);
94263320SdimIndex: lib/CodeGen/AsmPrinter/AsmPrinter.cpp
95263320Sdim===================================================================
96263320Sdim--- lib/CodeGen/AsmPrinter/AsmPrinter.cpp
97263320Sdim+++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp
98263320Sdim@@ -23,6 +23,7 @@
99263320Sdim #include "llvm/CodeGen/MachineConstantPool.h"
100263320Sdim #include "llvm/CodeGen/MachineFrameInfo.h"
101263320Sdim #include "llvm/CodeGen/MachineFunction.h"
102263320Sdim+#include "llvm/CodeGen/MachineInstrBundle.h"
103263320Sdim #include "llvm/CodeGen/MachineJumpTableInfo.h"
104263320Sdim #include "llvm/CodeGen/MachineLoopInfo.h"
105263320Sdim #include "llvm/CodeGen/MachineModuleInfo.h"
106263320Sdim@@ -2221,14 +2222,13 @@ isBlockOnlyReachableByFallthrough(const MachineBas
107263320Sdim     if (!MI.isBranch() || MI.isIndirectBranch())
108263320Sdim       return false;
109263320Sdim 
110263320Sdim-    // If we are the operands of one of the branches, this is not
111263320Sdim-    // a fall through.
112263320Sdim-    for (MachineInstr::mop_iterator OI = MI.operands_begin(),
113263320Sdim-           OE = MI.operands_end(); OI != OE; ++OI) {
114263320Sdim-      const MachineOperand& OP = *OI;
115263320Sdim-      if (OP.isJTI())
116263320Sdim+    // If we are the operands of one of the branches, this is not a fall
117263320Sdim+    // through. Note that targets with delay slots will usually bundle
118263320Sdim+    // terminators with the delay slot instruction.
119263320Sdim+    for (ConstMIBundleOperands OP(&MI); OP.isValid(); ++OP) {
120263320Sdim+      if (OP->isJTI())
121263320Sdim         return false;
122263320Sdim-      if (OP.isMBB() && OP.getMBB() == MBB)
123263320Sdim+      if (OP->isMBB() && OP->getMBB() == MBB)
124263320Sdim         return false;
125263320Sdim     }
126263320Sdim   }
127