Skip to content

Commit

Permalink
Handle bundled terminators in isBlockOnlyReachableByFallthrough.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stoklund committed Jan 12, 2014
1 parent 9b435fe commit 1995b9f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 42 deletions.
14 changes: 7 additions & 7 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBundle.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
Expand Down Expand Up @@ -2216,14 +2217,13 @@ isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const {
if (!MI.isBranch() || MI.isIndirectBranch())
return false;

// If we are the operands of one of the branches, this is not
// a fall through.
for (MachineInstr::mop_iterator OI = MI.operands_begin(),
OE = MI.operands_end(); OI != OE; ++OI) {
const MachineOperand& OP = *OI;
if (OP.isJTI())
// If we are the operands of one of the branches, this is not a fall
// through. Note that targets with delay slots will usually bundle
// terminators with the delay slot instruction.
for (ConstMIBundleOperands OP(&MI); OP.isValid(); ++OP) {
if (OP->isJTI())
return false;
if (OP.isMBB() && OP.getMBB() == MBB)
if (OP->isMBB() && OP->getMBB() == MBB)
return false;
}
}
Expand Down
35 changes: 0 additions & 35 deletions llvm/lib/Target/Sparc/SparcAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ namespace {
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
unsigned AsmVariant, const char *ExtraCode,
raw_ostream &O);

virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB)
const;

};
} // end of anonymous namespace

Expand Down Expand Up @@ -391,37 +387,6 @@ bool SparcAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
return false;
}

/// isBlockOnlyReachableByFallthough - Return true if the basic block has
/// exactly one predecessor and the control transfer mechanism between
/// the predecessor and this block is a fall-through.
///
/// This overrides AsmPrinter's implementation to handle delay slots.
bool SparcAsmPrinter::
isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const {
// If this is a landing pad, it isn't a fall through. If it has no preds,
// then nothing falls through to it.
if (MBB->isLandingPad() || MBB->pred_empty())
return false;

// If there isn't exactly one predecessor, it can't be a fall through.
MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(), PI2 = PI;
++PI2;
if (PI2 != MBB->pred_end())
return false;

// The predecessor has to be immediately before this block.
const MachineBasicBlock *Pred = *PI;

if (!Pred->isLayoutSuccessor(MBB))
return false;

// Check if the last terminator is an unconditional branch.
MachineBasicBlock::const_iterator I = Pred->end();
while (I != Pred->begin() && !(--I)->isTerminator())
; // Noop
return I == Pred->end() || !I->isBarrier();
}

// Force static initialization.
extern "C" void LLVMInitializeSparcAsmPrinter() {
RegisterAsmPrinter<SparcAsmPrinter> X(TheSparcTarget);
Expand Down
23 changes: 23 additions & 0 deletions llvm/test/CodeGen/SPARC/missinglabel.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; RUN: llc < %s -verify-machineinstrs | FileCheck %s
target datalayout = "E-m:e-i64:64-n32:64-S128"
target triple = "sparc64-unknown-linux-gnu"

define void @f() align 2 {
entry:
; CHECK: %xcc, .LBB0_1
%cmp = icmp eq i64 undef, 0
br i1 %cmp, label %targetblock, label %cond.false

cond.false:
unreachable

; CHECK: .LBB0_1: ! %targetblock
targetblock:
br i1 undef, label %cond.false.i83, label %exit.i85

cond.false.i83:
unreachable

exit.i85:
unreachable
}

0 comments on commit 1995b9f

Please sign in to comment.