mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 13:11:39 +01:00
[WebAssembly] Simplify iterator navigations (NFC)
Summary: - Replaces some uses of `MachineFunction::iterator(MBB)` with `MBB->getIterator()` and `MachineBasicBlock::iterator(MI)` with `MI->getIterator()`, which are simpler. - Replaces some uses of `std::prev` of `std::next` that takes a MachineFunction or MachineBasicBlock iterator with `getPrevNode` and `getNextNode`, which are also simpler. Reviewers: sbc100 Subscribers: dschuff, sunfish, jgravelle-google, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58913 llvm-svn: 355444
This commit is contained in:
parent
116895ffdc
commit
ac320d3a64
@ -229,7 +229,7 @@ void WebAssemblyCFGStackify::placeBlockMarker(MachineBasicBlock &MBB) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
assert(&MBB != &MF.front() && "Header blocks shouldn't have predecessors");
|
assert(&MBB != &MF.front() && "Header blocks shouldn't have predecessors");
|
||||||
MachineBasicBlock *LayoutPred = &*std::prev(MachineFunction::iterator(&MBB));
|
MachineBasicBlock *LayoutPred = MBB.getPrevNode();
|
||||||
|
|
||||||
// If the nearest common dominator is inside a more deeply nested context,
|
// If the nearest common dominator is inside a more deeply nested context,
|
||||||
// walk out to the nearest scope which isn't more deeply nested.
|
// walk out to the nearest scope which isn't more deeply nested.
|
||||||
@ -237,7 +237,7 @@ void WebAssemblyCFGStackify::placeBlockMarker(MachineBasicBlock &MBB) {
|
|||||||
if (MachineBasicBlock *ScopeTop = ScopeTops[I->getNumber()]) {
|
if (MachineBasicBlock *ScopeTop = ScopeTops[I->getNumber()]) {
|
||||||
if (ScopeTop->getNumber() > Header->getNumber()) {
|
if (ScopeTop->getNumber() > Header->getNumber()) {
|
||||||
// Skip over an intervening scope.
|
// Skip over an intervening scope.
|
||||||
I = std::next(MachineFunction::iterator(ScopeTop));
|
I = std::next(ScopeTop->getIterator());
|
||||||
} else {
|
} else {
|
||||||
// We found a scope level at an appropriate depth.
|
// We found a scope level at an appropriate depth.
|
||||||
Header = ScopeTop;
|
Header = ScopeTop;
|
||||||
@ -259,8 +259,7 @@ void WebAssemblyCFGStackify::placeBlockMarker(MachineBasicBlock &MBB) {
|
|||||||
// the BLOCK.
|
// the BLOCK.
|
||||||
if (MI.getOpcode() == WebAssembly::LOOP ||
|
if (MI.getOpcode() == WebAssembly::LOOP ||
|
||||||
MI.getOpcode() == WebAssembly::TRY) {
|
MI.getOpcode() == WebAssembly::TRY) {
|
||||||
auto *BottomBB =
|
auto *BottomBB = BeginToEnd[&MI]->getParent()->getPrevNode();
|
||||||
&*std::prev(MachineFunction::iterator(BeginToEnd[&MI]->getParent()));
|
|
||||||
if (MBB.getNumber() > BottomBB->getNumber())
|
if (MBB.getNumber() > BottomBB->getNumber())
|
||||||
AfterSet.insert(&MI);
|
AfterSet.insert(&MI);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
@ -373,13 +372,13 @@ void WebAssemblyCFGStackify::placeLoopMarker(MachineBasicBlock &MBB) {
|
|||||||
// The operand of a LOOP is the first block after the loop. If the loop is the
|
// The operand of a LOOP is the first block after the loop. If the loop is the
|
||||||
// bottom of the function, insert a dummy block at the end.
|
// bottom of the function, insert a dummy block at the end.
|
||||||
MachineBasicBlock *Bottom = WebAssembly::getBottom(Loop);
|
MachineBasicBlock *Bottom = WebAssembly::getBottom(Loop);
|
||||||
auto Iter = std::next(MachineFunction::iterator(Bottom));
|
auto Iter = std::next(Bottom->getIterator());
|
||||||
if (Iter == MF.end()) {
|
if (Iter == MF.end()) {
|
||||||
MachineBasicBlock *Label = MF.CreateMachineBasicBlock();
|
MachineBasicBlock *Label = MF.CreateMachineBasicBlock();
|
||||||
// Give it a fake predecessor so that AsmPrinter prints its label.
|
// Give it a fake predecessor so that AsmPrinter prints its label.
|
||||||
Label->addSuccessor(Label);
|
Label->addSuccessor(Label);
|
||||||
MF.push_back(Label);
|
MF.push_back(Label);
|
||||||
Iter = std::next(MachineFunction::iterator(Bottom));
|
Iter = std::next(Bottom->getIterator());
|
||||||
}
|
}
|
||||||
MachineBasicBlock *AfterLoop = &*Iter;
|
MachineBasicBlock *AfterLoop = &*Iter;
|
||||||
|
|
||||||
@ -457,19 +456,18 @@ void WebAssemblyCFGStackify::placeTryMarker(MachineBasicBlock &MBB) {
|
|||||||
assert(WE);
|
assert(WE);
|
||||||
MachineBasicBlock *Bottom = WebAssembly::getBottom(WE);
|
MachineBasicBlock *Bottom = WebAssembly::getBottom(WE);
|
||||||
|
|
||||||
auto Iter = std::next(MachineFunction::iterator(Bottom));
|
auto Iter = std::next(Bottom->getIterator());
|
||||||
if (Iter == MF.end()) {
|
if (Iter == MF.end()) {
|
||||||
MachineBasicBlock *Label = MF.CreateMachineBasicBlock();
|
MachineBasicBlock *Label = MF.CreateMachineBasicBlock();
|
||||||
// Give it a fake predecessor so that AsmPrinter prints its label.
|
// Give it a fake predecessor so that AsmPrinter prints its label.
|
||||||
Label->addSuccessor(Label);
|
Label->addSuccessor(Label);
|
||||||
MF.push_back(Label);
|
MF.push_back(Label);
|
||||||
Iter = std::next(MachineFunction::iterator(Bottom));
|
Iter = std::next(Bottom->getIterator());
|
||||||
}
|
}
|
||||||
MachineBasicBlock *Cont = &*Iter;
|
MachineBasicBlock *Cont = &*Iter;
|
||||||
|
|
||||||
assert(Cont != &MF.front());
|
assert(Cont != &MF.front());
|
||||||
MachineBasicBlock *LayoutPred =
|
MachineBasicBlock *LayoutPred = Cont->getPrevNode();
|
||||||
&*std::prev(MachineFunction::iterator(Cont));
|
|
||||||
|
|
||||||
// If the nearest common dominator is inside a more deeply nested context,
|
// If the nearest common dominator is inside a more deeply nested context,
|
||||||
// walk out to the nearest scope which isn't more deeply nested.
|
// walk out to the nearest scope which isn't more deeply nested.
|
||||||
@ -477,7 +475,7 @@ void WebAssemblyCFGStackify::placeTryMarker(MachineBasicBlock &MBB) {
|
|||||||
if (MachineBasicBlock *ScopeTop = ScopeTops[I->getNumber()]) {
|
if (MachineBasicBlock *ScopeTop = ScopeTops[I->getNumber()]) {
|
||||||
if (ScopeTop->getNumber() > Header->getNumber()) {
|
if (ScopeTop->getNumber() > Header->getNumber()) {
|
||||||
// Skip over an intervening scope.
|
// Skip over an intervening scope.
|
||||||
I = std::next(MachineFunction::iterator(ScopeTop));
|
I = std::next(ScopeTop->getIterator());
|
||||||
} else {
|
} else {
|
||||||
// We found a scope level at an appropriate depth.
|
// We found a scope level at an appropriate depth.
|
||||||
Header = ScopeTop;
|
Header = ScopeTop;
|
||||||
@ -633,8 +631,7 @@ void WebAssemblyCFGStackify::removeUnnecessaryInstrs(MachineFunction &MF) {
|
|||||||
|
|
||||||
MachineBasicBlock *TBB = nullptr, *FBB = nullptr;
|
MachineBasicBlock *TBB = nullptr, *FBB = nullptr;
|
||||||
SmallVector<MachineOperand, 4> Cond;
|
SmallVector<MachineOperand, 4> Cond;
|
||||||
MachineBasicBlock *EHPadLayoutPred =
|
MachineBasicBlock *EHPadLayoutPred = MBB.getPrevNode();
|
||||||
&*std::prev(MachineFunction::iterator(&MBB));
|
|
||||||
MachineBasicBlock *Cont = BeginToEnd[EHPadToTry[&MBB]]->getParent();
|
MachineBasicBlock *Cont = BeginToEnd[EHPadToTry[&MBB]]->getParent();
|
||||||
bool Analyzable = !TII.analyzeBranch(*EHPadLayoutPred, TBB, FBB, Cond);
|
bool Analyzable = !TII.analyzeBranch(*EHPadLayoutPred, TBB, FBB, Cond);
|
||||||
if (Analyzable && ((Cond.empty() && TBB && TBB == Cont) ||
|
if (Analyzable && ((Cond.empty() && TBB && TBB == Cont) ||
|
||||||
@ -663,8 +660,7 @@ void WebAssemblyCFGStackify::removeUnnecessaryInstrs(MachineFunction &MF) {
|
|||||||
MachineBasicBlock *TryBB = Try->getParent();
|
MachineBasicBlock *TryBB = Try->getParent();
|
||||||
MachineBasicBlock *Cont = EndTry->getParent();
|
MachineBasicBlock *Cont = EndTry->getParent();
|
||||||
int64_t RetType = Try->getOperand(0).getImm();
|
int64_t RetType = Try->getOperand(0).getImm();
|
||||||
for (auto B = MachineBasicBlock::iterator(Try),
|
for (auto B = Try->getIterator(), E = std::next(EndTry->getIterator());
|
||||||
E = std::next(MachineBasicBlock::iterator(EndTry));
|
|
||||||
B != TryBB->begin() && E != Cont->end() &&
|
B != TryBB->begin() && E != Cont->end() &&
|
||||||
std::prev(B)->getOpcode() == WebAssembly::BLOCK &&
|
std::prev(B)->getOpcode() == WebAssembly::BLOCK &&
|
||||||
E->getOpcode() == WebAssembly::END_BLOCK &&
|
E->getOpcode() == WebAssembly::END_BLOCK &&
|
||||||
|
@ -274,7 +274,7 @@ bool WebAssemblyExplicitLocals::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
if (!MFI.isVRegStackified(OldReg)) {
|
if (!MFI.isVRegStackified(OldReg)) {
|
||||||
const TargetRegisterClass *RC = MRI.getRegClass(OldReg);
|
const TargetRegisterClass *RC = MRI.getRegClass(OldReg);
|
||||||
unsigned NewReg = MRI.createVirtualRegister(RC);
|
unsigned NewReg = MRI.createVirtualRegister(RC);
|
||||||
auto InsertPt = std::next(MachineBasicBlock::iterator(&MI));
|
auto InsertPt = std::next(MI.getIterator());
|
||||||
if (MI.getOpcode() == WebAssembly::IMPLICIT_DEF) {
|
if (MI.getOpcode() == WebAssembly::IMPLICIT_DEF) {
|
||||||
MI.eraseFromParent();
|
MI.eraseFromParent();
|
||||||
Changed = true;
|
Changed = true;
|
||||||
|
@ -319,8 +319,7 @@ bool LoopFixer::run() {
|
|||||||
|
|
||||||
// This is a successor we need to rewrite.
|
// This is a successor we need to rewrite.
|
||||||
MachineBasicBlock *Split = MF.CreateMachineBasicBlock();
|
MachineBasicBlock *Split = MF.CreateMachineBasicBlock();
|
||||||
MF.insert(MBB->isLayoutSuccessor(Succ) ? MachineFunction::iterator(Succ)
|
MF.insert(MBB->isLayoutSuccessor(Succ) ? Succ->getIterator() : MF.end(),
|
||||||
: MF.end(),
|
|
||||||
Split);
|
Split);
|
||||||
MLI.changeLoopFor(Split, Loop);
|
MLI.changeLoopFor(Split, Loop);
|
||||||
|
|
||||||
|
@ -358,8 +358,7 @@ static MachineBasicBlock *LowerFPToInt(MachineInstr &MI, DebugLoc DL,
|
|||||||
F->insert(It, DoneMBB);
|
F->insert(It, DoneMBB);
|
||||||
|
|
||||||
// Transfer the remainder of BB and its successor edges to DoneMBB.
|
// Transfer the remainder of BB and its successor edges to DoneMBB.
|
||||||
DoneMBB->splice(DoneMBB->begin(), BB,
|
DoneMBB->splice(DoneMBB->begin(), BB, std::next(MI.getIterator()), BB->end());
|
||||||
std::next(MachineBasicBlock::iterator(MI)), BB->end());
|
|
||||||
DoneMBB->transferSuccessorsAndUpdatePHIs(BB);
|
DoneMBB->transferSuccessorsAndUpdatePHIs(BB);
|
||||||
|
|
||||||
BB->addSuccessor(TrueMBB);
|
BB->addSuccessor(TrueMBB);
|
||||||
|
@ -132,7 +132,7 @@ bool WebAssemblyLateEHPrepare::removeUnnecessaryUnreachables(
|
|||||||
// another BB that should eventually lead to an unreachable. Delete it
|
// another BB that should eventually lead to an unreachable. Delete it
|
||||||
// because throw itself is a terminator, and also delete successors if
|
// because throw itself is a terminator, and also delete successors if
|
||||||
// any.
|
// any.
|
||||||
MBB.erase(std::next(MachineBasicBlock::iterator(MI)), MBB.end());
|
MBB.erase(std::next(MI.getIterator()), MBB.end());
|
||||||
SmallVector<MachineBasicBlock *, 8> Succs(MBB.succ_begin(),
|
SmallVector<MachineBasicBlock *, 8> Succs(MBB.succ_begin(),
|
||||||
MBB.succ_end());
|
MBB.succ_end());
|
||||||
for (auto *Succ : Succs)
|
for (auto *Succ : Succs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user