#include "llvm/CodeGen/SlotIndexes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/Support/Debug.h"
const MachineFunction *MF = getParent();
MCContext &Ctx = MF->getContext();
const char *Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix();
- CachedMCSymbol = Ctx.GetOrCreateSymbol(Twine(Prefix) + "BB" +
+ CachedMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB" +
Twine(MF->getFunctionNumber()) +
"_" + Twine(getNumber()));
}
return I;
}
-MachineBasicBlock::const_iterator
-MachineBasicBlock::getFirstTerminator() const {
- const_iterator B = begin(), E = end(), I = E;
+MachineBasicBlock::instr_iterator MachineBasicBlock::getFirstInstrTerminator() {
+ instr_iterator B = instr_begin(), E = instr_end(), I = E;
while (I != B && ((--I)->isTerminator() || I->isDebugValue()))
; /*noop */
while (I != E && !I->isTerminator())
return I;
}
-MachineBasicBlock::instr_iterator MachineBasicBlock::getFirstInstrTerminator() {
- instr_iterator B = instr_begin(), E = instr_end(), I = E;
- while (I != B && ((--I)->isTerminator() || I->isDebugValue()))
- ; /*noop */
- while (I != E && !I->isTerminator())
+MachineBasicBlock::iterator MachineBasicBlock::getFirstNonDebugInstr() {
+ // Skip over begin-of-block dbg_value instructions.
+ iterator I = begin(), E = end();
+ while (I != E && I->isDebugValue())
++I;
return I;
}
return end();
}
-MachineBasicBlock::const_iterator
-MachineBasicBlock::getLastNonDebugInstr() const {
- // Skip over end-of-block dbg_value instructions.
- const_instr_iterator B = instr_begin(), I = instr_end();
- while (I != B) {
- --I;
- // Return instruction that starts a bundle.
- if (I->isDebugValue() || I->isInsideBundle())
- continue;
- return I;
- }
- // The block is all debug values.
- return end();
-}
-
const MachineBasicBlock *MachineBasicBlock::getLandingPadSuccessor() const {
// A block with a landing pad successor only has one other successor.
if (succ_size() > 2)
<< " is null\n";
return;
}
+ const Function *F = MF->getFunction();
+ const Module *M = F ? F->getParent() : nullptr;
+ ModuleSlotTracker MST(M);
+ print(OS, MST, Indexes);
+}
+
+void MachineBasicBlock::print(raw_ostream &OS, ModuleSlotTracker &MST,
+ SlotIndexes *Indexes) const {
+ const MachineFunction *MF = getParent();
+ if (!MF) {
+ OS << "Can't print out MachineBasicBlock because parent MachineFunction"
+ << " is null\n";
+ return;
+ }
if (Indexes)
OS << Indexes->getMBBStartIdx(this) << '\t';
const char *Comma = "";
if (const BasicBlock *LBB = getBasicBlock()) {
OS << Comma << "derived from LLVM BB ";
- LBB->printAsOperand(OS, /*PrintType=*/false);
+ LBB->printAsOperand(OS, /*PrintType=*/false, MST);
Comma = ", ";
}
if (isLandingPad()) { OS << Comma << "EH LANDING PAD"; Comma = ", "; }
OS << '\t';
if (I->isInsideBundle())
OS << " * ";
- I->print(OS);
+ I->print(OS, MST);
}
// Print the successors of this block according to the CFG.
/// instructions after (searching just for defs) MI.
MachineBasicBlock::LivenessQueryResult
MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI,
- unsigned Reg, MachineInstr *MI,
- unsigned Neighborhood) {
+ unsigned Reg, const_iterator Before,
+ unsigned Neighborhood) const {
unsigned N = Neighborhood;
- MachineBasicBlock *MBB = MI->getParent();
-
- // Start by searching backwards from MI, looking for kills, reads or defs.
- MachineBasicBlock::iterator I(MI);
+ // Start by searching backwards from Before, looking for kills, reads or defs.
+ const_iterator I(Before);
// If this is the first insn in the block, don't search backwards.
- if (I != MBB->begin()) {
+ if (I != begin()) {
do {
--I;
MachineOperandIteratorBase::PhysRegInfo Analysis =
- MIOperands(I).analyzePhysReg(Reg, TRI);
+ ConstMIOperands(I).analyzePhysReg(Reg, TRI);
if (Analysis.Defines)
// Outputs happen after inputs so they take precedence if both are
// Defined or read without a previous kill - live.
return Analysis.Reads ? LQR_Live : LQR_OverlappingLive;
- } while (I != MBB->begin() && --N > 0);
+ } while (I != begin() && --N > 0);
}
// Did we get to the start of the block?
- if (I == MBB->begin()) {
+ if (I == begin()) {
// If so, the register's state is definitely defined by the live-in state.
for (MCRegAliasIterator RAI(Reg, TRI, /*IncludeSelf=*/true);
RAI.isValid(); ++RAI) {
- if (MBB->isLiveIn(*RAI))
+ if (isLiveIn(*RAI))
return (*RAI == Reg) ? LQR_Live : LQR_OverlappingLive;
}
N = Neighborhood;
- // Try searching forwards from MI, looking for reads or defs.
- I = MachineBasicBlock::iterator(MI);
+ // Try searching forwards from Before, looking for reads or defs.
+ I = const_iterator(Before);
// If this is the last insn in the block, don't search forwards.
- if (I != MBB->end()) {
- for (++I; I != MBB->end() && N > 0; ++I, --N) {
+ if (I != end()) {
+ for (++I; I != end() && N > 0; ++I, --N) {
MachineOperandIteratorBase::PhysRegInfo Analysis =
- MIOperands(I).analyzePhysReg(Reg, TRI);
+ ConstMIOperands(I).analyzePhysReg(Reg, TRI);
if (Analysis.ReadsOverlap)
// Used, therefore must have been live.