Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 6e5736e

Browse files
committed
CodeGen: MachineInstr::getIterator() => getInstrIterator(), NFC
Delete MachineInstr::getIterator(), since the term "iterator" is overloaded when talking about MachineInstr. - Downcast to ilist_node in iplist::getNextNode() and getPrevNode() so that ilist_node::getIterator() is still available. - Add it back as MachineInstr::getInstrIterator(). This matches the naming in MachineBasicBlock. - Add MachineInstr::getBundleIterator(). This is explicitly called "bundle" (not matching MachineBasicBlock) to disintinguish it clearly from ilist_node::getIterator(). - Update all calls. Some of these I switched to `auto` to remove boiler-plate, since the new name is clear about the type. There was one call I updated that looked fishy, but it wasn't clear what the right answer was. This was in X86FrameLowering::inlineStackProbe(), added in r252578 in lib/Target/X86/X86FrameLowering.cpp. I opted to leave the behaviour unchanged, but I'll reply to the original commit on the list in a moment. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261504 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1d95ab2 commit 6e5736e

21 files changed

+69
-54
lines changed

include/llvm/ADT/ilist.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ class iplist : public Traits {
638638

639639
/// \brief Get the previous node, or \c nullptr for the list head.
640640
NodeTy *getPrevNode(NodeTy &N) const {
641-
auto I = N.getIterator();
641+
auto I = static_cast<ilist_node<NodeTy> &>(N).getIterator();
642642
if (I == begin())
643643
return nullptr;
644644
return &*std::prev(I);
@@ -650,7 +650,7 @@ class iplist : public Traits {
650650

651651
/// \brief Get the next node, or \c nullptr for the list tail.
652652
NodeTy *getNextNode(NodeTy &N) const {
653-
auto Next = std::next(N.getIterator());
653+
auto Next = std::next(static_cast<ilist_node<NodeTy> &>(N).getIterator());
654654
if (Next == end())
655655
return nullptr;
656656
return &*Next;

include/llvm/CodeGen/MachineInstr.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/ADT/iterator_range.h"
2626
#include "llvm/Analysis/AliasAnalysis.h"
2727
#include "llvm/CodeGen/MachineOperand.h"
28+
#include "llvm/CodeGen/MachineInstrBundleIterator.h"
2829
#include "llvm/IR/DebugInfo.h"
2930
#include "llvm/IR/DebugLoc.h"
3031
#include "llvm/IR/InlineAsm.h"
@@ -139,6 +140,21 @@ class MachineInstr
139140
const MachineBasicBlock* getParent() const { return Parent; }
140141
MachineBasicBlock* getParent() { return Parent; }
141142

143+
// Disallow getIterator(), since it's ambiguous.
144+
void getIterator() = delete;
145+
typedef ilist_iterator<MachineInstr> instr_iterator;
146+
typedef ilist_iterator<const MachineInstr> const_instr_iterator;
147+
instr_iterator getInstrIterator() { return instr_iterator(this); }
148+
const_instr_iterator getInstrIterator() const {
149+
return const_instr_iterator(this);
150+
}
151+
typedef MachineInstrBundleIterator<MachineInstr> bundle_iterator;
152+
typedef MachineInstrBundleIterator<const MachineInstr> const_bundle_iterator;
153+
bundle_iterator getBundleIterator() { return bundle_iterator(this); }
154+
const_bundle_iterator getBundleIterator() const {
155+
return const_bundle_iterator(this);
156+
}
157+
142158
/// Return the asm printer flags bitvector.
143159
uint8_t getAsmPrinterFlags() const { return AsmPrinterFlags; }
144160

include/llvm/CodeGen/MachineInstrBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ class MIBundleBuilder {
472472
if (I == Begin) {
473473
if (!empty())
474474
MI->bundleWithSucc();
475-
Begin = MI->getIterator();
475+
Begin = MI->getInstrIterator();
476476
return *this;
477477
}
478478
if (I == End) {

include/llvm/CodeGen/MachineInstrBundle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ class MachineOperandIteratorBase {
116116
///
117117
explicit MachineOperandIteratorBase(MachineInstr *MI, bool WholeBundle) {
118118
if (WholeBundle) {
119-
InstrI = getBundleStart(MI)->getIterator();
119+
InstrI = getBundleStart(MI)->getInstrIterator();
120120
InstrE = MI->getParent()->instr_end();
121121
} else {
122-
InstrI = InstrE = MI->getIterator();
122+
InstrI = InstrE = MI->getInstrIterator();
123123
++InstrE;
124124
}
125125
OpI = InstrI->operands_begin();

lib/CodeGen/DFAPacketizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ VLIWPacketizerList::~VLIWPacketizerList() {
198198
void VLIWPacketizerList::endPacket(MachineBasicBlock *MBB, MachineInstr *MI) {
199199
if (CurrentPacketMIs.size() > 1) {
200200
MachineInstr *MIFirst = CurrentPacketMIs.front();
201-
finalizeBundle(*MBB, MIFirst->getIterator(), MI->getIterator());
201+
finalizeBundle(*MBB, MIFirst->getInstrIterator(), MI->getInstrIterator());
202202
}
203203
CurrentPacketMIs.clear();
204204
ResourceTracker->clearResources();

lib/CodeGen/MachineCopyPropagation.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ static bool NoInterveningSideEffect(const MachineInstr *CopyMI,
9090
if (MI->getParent() != MBB)
9191
return false;
9292

93-
for (MachineBasicBlock::const_iterator I = std::next(CopyMI->getIterator()),
94-
E = MBB->end(), E2 = MI->getIterator(); I != E && I != E2; ++I) {
93+
for (MachineBasicBlock::const_instr_iterator
94+
I = std::next(CopyMI->getInstrIterator()),
95+
E = MBB->instr_end(), E2 = MI->getInstrIterator();
96+
I != E && I != E2; ++I) {
9597
if (I->hasUnmodeledSideEffects() || I->isCall() ||
9698
I->isTerminator())
9799
return false;
@@ -163,8 +165,8 @@ void MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
163165

164166
// Clear any kills of Def between CopyMI and MI. This extends the
165167
// live range.
166-
for (MachineInstr &MMI
167-
: make_range(CopyMI->getIterator(), MI->getIterator()))
168+
for (MachineInstr &MMI :
169+
make_range(CopyMI->getInstrIterator(), MI->getInstrIterator()))
168170
MMI.clearRegisterKills(Def, TRI);
169171

170172
MI->eraseFromParent();

lib/CodeGen/MachineInstr.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ MachineInstr::mergeMemRefsWith(const MachineInstr& Other) {
934934

935935
bool MachineInstr::hasPropertyInBundle(unsigned Mask, QueryType Type) const {
936936
assert(!isBundledWithPred() && "Must be called on bundle header");
937-
for (MachineBasicBlock::const_instr_iterator MII = getIterator();; ++MII) {
937+
for (auto MII = getInstrIterator();; ++MII) {
938938
if (MII->getDesc().getFlags() & Mask) {
939939
if (Type == AnyInBundle)
940940
return true;
@@ -958,10 +958,10 @@ bool MachineInstr::isIdenticalTo(const MachineInstr *Other,
958958

959959
if (isBundle()) {
960960
// Both instructions are bundles, compare MIs inside the bundle.
961-
MachineBasicBlock::const_instr_iterator I1 = getIterator();
962-
MachineBasicBlock::const_instr_iterator E1 = getParent()->instr_end();
963-
MachineBasicBlock::const_instr_iterator I2 = Other->getIterator();
964-
MachineBasicBlock::const_instr_iterator E2= Other->getParent()->instr_end();
961+
auto I1 = getInstrIterator();
962+
auto E1 = getParent()->instr_end();
963+
auto I2 = Other->getInstrIterator();
964+
auto E2 = Other->getParent()->instr_end();
965965
while (++I1 != E1 && I1->isInsideBundle()) {
966966
++I2;
967967
if (I2 == E2 || !I2->isInsideBundle() || !I1->isIdenticalTo(&*I2, Check))
@@ -1069,35 +1069,31 @@ unsigned MachineInstr::getNumExplicitOperands() const {
10691069
void MachineInstr::bundleWithPred() {
10701070
assert(!isBundledWithPred() && "MI is already bundled with its predecessor");
10711071
setFlag(BundledPred);
1072-
MachineBasicBlock::instr_iterator Pred = getIterator();
1073-
--Pred;
1072+
auto Pred = --getInstrIterator();
10741073
assert(!Pred->isBundledWithSucc() && "Inconsistent bundle flags");
10751074
Pred->setFlag(BundledSucc);
10761075
}
10771076

10781077
void MachineInstr::bundleWithSucc() {
10791078
assert(!isBundledWithSucc() && "MI is already bundled with its successor");
10801079
setFlag(BundledSucc);
1081-
MachineBasicBlock::instr_iterator Succ = getIterator();
1082-
++Succ;
1080+
auto Succ = ++getInstrIterator();
10831081
assert(!Succ->isBundledWithPred() && "Inconsistent bundle flags");
10841082
Succ->setFlag(BundledPred);
10851083
}
10861084

10871085
void MachineInstr::unbundleFromPred() {
10881086
assert(isBundledWithPred() && "MI isn't bundled with its predecessor");
10891087
clearFlag(BundledPred);
1090-
MachineBasicBlock::instr_iterator Pred = getIterator();
1091-
--Pred;
1088+
auto Pred = --getInstrIterator();
10921089
assert(Pred->isBundledWithSucc() && "Inconsistent bundle flags");
10931090
Pred->clearFlag(BundledSucc);
10941091
}
10951092

10961093
void MachineInstr::unbundleFromSucc() {
10971094
assert(isBundledWithSucc() && "MI isn't bundled with its successor");
10981095
clearFlag(BundledSucc);
1099-
MachineBasicBlock::instr_iterator Succ = getIterator();
1100-
++Succ;
1096+
auto Succ = ++getInstrIterator();
11011097
assert(Succ->isBundledWithPred() && "Inconsistent bundle flags");
11021098
Succ->clearFlag(BundledPred);
11031099
}
@@ -1232,7 +1228,7 @@ const TargetRegisterClass *MachineInstr::getRegClassConstraintEffect(
12321228
/// Return the number of instructions inside the MI bundle, not counting the
12331229
/// header instruction.
12341230
unsigned MachineInstr::getBundleSize() const {
1235-
MachineBasicBlock::const_instr_iterator I = getIterator();
1231+
auto I = getInstrIterator();
12361232
unsigned Size = 0;
12371233
while (I->isBundledWithSucc()) {
12381234
++Size;

lib/CodeGen/ProcessImplicitDefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ void ProcessImplicitDefs::processImplicitDef(MachineInstr *MI) {
9696

9797
// This is a physreg implicit-def.
9898
// Look for the first instruction to use or define an alias.
99-
MachineBasicBlock::instr_iterator UserMI = MI->getIterator();
100-
MachineBasicBlock::instr_iterator UserE = MI->getParent()->instr_end();
99+
auto UserMI = MI->getInstrIterator();
100+
auto UserE = MI->getParent()->instr_end();
101101
bool Found = false;
102102
for (++UserMI; UserMI != UserE; ++UserMI) {
103103
for (MachineOperand &MO : UserMI->operands()) {

lib/CodeGen/ScheduleDAGInstrs.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,8 @@ static void toggleBundleKillFlag(MachineInstr *MI, unsigned Reg,
12001200
// Once we set a kill flag on an instruction, we bail out, as otherwise we
12011201
// might set it on too many operands. We will clear as many flags as we
12021202
// can though.
1203-
MachineBasicBlock::instr_iterator Begin = MI->getIterator();
1204-
MachineBasicBlock::instr_iterator End = getBundleEnd(MI);
1203+
auto Begin = MI->getInstrIterator();
1204+
auto End = getBundleEnd(MI);
12051205
while (Begin != End) {
12061206
for (MachineOperand &MO : (--End)->operands()) {
12071207
if (!MO.isReg() || MO.isDef() || Reg != MO.getReg())
@@ -1334,8 +1334,8 @@ void ScheduleDAGInstrs::fixupKills(MachineBasicBlock *MBB) {
13341334
toggleKillFlag(MI, MO);
13351335
DEBUG(MI->dump());
13361336
DEBUG(if (MI->getOpcode() == TargetOpcode::BUNDLE) {
1337-
MachineBasicBlock::instr_iterator Begin = MI->getIterator();
1338-
MachineBasicBlock::instr_iterator End = getBundleEnd(MI);
1337+
auto Begin = MI->getInstrIterator();
1338+
auto End = getBundleEnd(MI);
13391339
while (++Begin != End)
13401340
DEBUG(Begin->dump());
13411341
});

lib/Target/AArch64/AArch64CleanupLocalDynamicTLSPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct LDTLSCleanup : public MachineFunctionPass {
118118

119119
// Insert a copy from X0 to TLSBaseAddrReg for later.
120120
MachineInstr *Copy =
121-
BuildMI(*I->getParent(), ++I->getIterator(), I->getDebugLoc(),
121+
BuildMI(*I->getParent(), ++I->getInstrIterator(), I->getDebugLoc(),
122122
TII->get(TargetOpcode::COPY), *TLSBaseAddrReg)
123123
.addReg(AArch64::X0);
124124

0 commit comments

Comments
 (0)