Skip to content

Commit 1995b9f

Browse files
committed
Handle bundled terminators in isBlockOnlyReachableByFallthrough.
Targets like SPARC and MIPS have delay slots and normally bundle the delay slot instruction with the corresponding terminator. Teach isBlockOnlyReachableByFallthrough to find any MBB operands on bundled terminators so SPARC doesn't need to specialize this function. llvm-svn: 199061
1 parent 9b435fe commit 1995b9f

File tree

3 files changed

+30
-42
lines changed

3 files changed

+30
-42
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/CodeGen/MachineConstantPool.h"
2323
#include "llvm/CodeGen/MachineFrameInfo.h"
2424
#include "llvm/CodeGen/MachineFunction.h"
25+
#include "llvm/CodeGen/MachineInstrBundle.h"
2526
#include "llvm/CodeGen/MachineJumpTableInfo.h"
2627
#include "llvm/CodeGen/MachineLoopInfo.h"
2728
#include "llvm/CodeGen/MachineModuleInfo.h"
@@ -2216,14 +2217,13 @@ isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const {
22162217
if (!MI.isBranch() || MI.isIndirectBranch())
22172218
return false;
22182219

2219-
// If we are the operands of one of the branches, this is not
2220-
// a fall through.
2221-
for (MachineInstr::mop_iterator OI = MI.operands_begin(),
2222-
OE = MI.operands_end(); OI != OE; ++OI) {
2223-
const MachineOperand& OP = *OI;
2224-
if (OP.isJTI())
2220+
// If we are the operands of one of the branches, this is not a fall
2221+
// through. Note that targets with delay slots will usually bundle
2222+
// terminators with the delay slot instruction.
2223+
for (ConstMIBundleOperands OP(&MI); OP.isValid(); ++OP) {
2224+
if (OP->isJTI())
22252225
return false;
2226-
if (OP.isMBB() && OP.getMBB() == MBB)
2226+
if (OP->isMBB() && OP->getMBB() == MBB)
22272227
return false;
22282228
}
22292229
}

llvm/lib/Target/Sparc/SparcAsmPrinter.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ namespace {
6565
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
6666
unsigned AsmVariant, const char *ExtraCode,
6767
raw_ostream &O);
68-
69-
virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB)
70-
const;
71-
7268
};
7369
} // end of anonymous namespace
7470

@@ -391,37 +387,6 @@ bool SparcAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
391387
return false;
392388
}
393389

394-
/// isBlockOnlyReachableByFallthough - Return true if the basic block has
395-
/// exactly one predecessor and the control transfer mechanism between
396-
/// the predecessor and this block is a fall-through.
397-
///
398-
/// This overrides AsmPrinter's implementation to handle delay slots.
399-
bool SparcAsmPrinter::
400-
isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const {
401-
// If this is a landing pad, it isn't a fall through. If it has no preds,
402-
// then nothing falls through to it.
403-
if (MBB->isLandingPad() || MBB->pred_empty())
404-
return false;
405-
406-
// If there isn't exactly one predecessor, it can't be a fall through.
407-
MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(), PI2 = PI;
408-
++PI2;
409-
if (PI2 != MBB->pred_end())
410-
return false;
411-
412-
// The predecessor has to be immediately before this block.
413-
const MachineBasicBlock *Pred = *PI;
414-
415-
if (!Pred->isLayoutSuccessor(MBB))
416-
return false;
417-
418-
// Check if the last terminator is an unconditional branch.
419-
MachineBasicBlock::const_iterator I = Pred->end();
420-
while (I != Pred->begin() && !(--I)->isTerminator())
421-
; // Noop
422-
return I == Pred->end() || !I->isBarrier();
423-
}
424-
425390
// Force static initialization.
426391
extern "C" void LLVMInitializeSparcAsmPrinter() {
427392
RegisterAsmPrinter<SparcAsmPrinter> X(TheSparcTarget);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc < %s -verify-machineinstrs | FileCheck %s
2+
target datalayout = "E-m:e-i64:64-n32:64-S128"
3+
target triple = "sparc64-unknown-linux-gnu"
4+
5+
define void @f() align 2 {
6+
entry:
7+
; CHECK: %xcc, .LBB0_1
8+
%cmp = icmp eq i64 undef, 0
9+
br i1 %cmp, label %targetblock, label %cond.false
10+
11+
cond.false:
12+
unreachable
13+
14+
; CHECK: .LBB0_1: ! %targetblock
15+
targetblock:
16+
br i1 undef, label %cond.false.i83, label %exit.i85
17+
18+
cond.false.i83:
19+
unreachable
20+
21+
exit.i85:
22+
unreachable
23+
}

0 commit comments

Comments
 (0)