Skip to content

Commit 38f39f8

Browse files
committed
Move LockstepIterator NFC>
1 parent 3679062 commit 38f39f8

File tree

1 file changed

+75
-75
lines changed

1 file changed

+75
-75
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,81 @@ static bool areIdenticalUpToCommutativity(const Instruction *I1,
16151615
return false;
16161616
}
16171617

1618+
namespace {
1619+
1620+
// LockstepReverseIterator - Iterates through instructions
1621+
// in a set of blocks in reverse order from the first non-terminator.
1622+
// For example (assume all blocks have size n):
1623+
// LockstepReverseIterator I([B1, B2, B3]);
1624+
// *I-- = [B1[n], B2[n], B3[n]];
1625+
// *I-- = [B1[n-1], B2[n-1], B3[n-1]];
1626+
// *I-- = [B1[n-2], B2[n-2], B3[n-2]];
1627+
// ...
1628+
class LockstepReverseIterator {
1629+
ArrayRef<BasicBlock*> Blocks;
1630+
SmallVector<Instruction*,4> Insts;
1631+
bool Fail;
1632+
1633+
public:
1634+
LockstepReverseIterator(ArrayRef<BasicBlock*> Blocks) : Blocks(Blocks) {
1635+
reset();
1636+
}
1637+
1638+
void reset() {
1639+
Fail = false;
1640+
Insts.clear();
1641+
for (auto *BB : Blocks) {
1642+
Instruction *Inst = BB->getTerminator();
1643+
for (Inst = Inst->getPrevNode(); Inst && isa<DbgInfoIntrinsic>(Inst);)
1644+
Inst = Inst->getPrevNode();
1645+
if (!Inst) {
1646+
// Block wasn't big enough.
1647+
Fail = true;
1648+
return;
1649+
}
1650+
Insts.push_back(Inst);
1651+
}
1652+
}
1653+
1654+
bool isValid() const {
1655+
return !Fail;
1656+
}
1657+
1658+
void operator--() {
1659+
if (Fail)
1660+
return;
1661+
for (auto *&Inst : Insts) {
1662+
for (Inst = Inst->getPrevNode(); Inst && isa<DbgInfoIntrinsic>(Inst);)
1663+
Inst = Inst->getPrevNode();
1664+
// Already at beginning of block.
1665+
if (!Inst) {
1666+
Fail = true;
1667+
return;
1668+
}
1669+
}
1670+
}
1671+
1672+
void operator++() {
1673+
if (Fail)
1674+
return;
1675+
for (auto *&Inst : Insts) {
1676+
for (Inst = Inst->getNextNode(); Inst && isa<DbgInfoIntrinsic>(Inst);)
1677+
Inst = Inst->getNextNode();
1678+
// Already at end of block.
1679+
if (!Inst) {
1680+
Fail = true;
1681+
return;
1682+
}
1683+
}
1684+
}
1685+
1686+
ArrayRef<Instruction*> operator * () const {
1687+
return Insts;
1688+
}
1689+
};
1690+
1691+
} // end anonymous namespace
1692+
16181693
/// Hoist any common code in the successor blocks up into the block. This
16191694
/// function guarantees that BB dominates all successors. If EqTermsOnly is
16201695
/// given, only perform hoisting in case both blocks only contain a terminator.
@@ -2176,81 +2251,6 @@ static void sinkLastInstruction(ArrayRef<BasicBlock*> Blocks) {
21762251
}
21772252
}
21782253

2179-
namespace {
2180-
2181-
// LockstepReverseIterator - Iterates through instructions
2182-
// in a set of blocks in reverse order from the first non-terminator.
2183-
// For example (assume all blocks have size n):
2184-
// LockstepReverseIterator I([B1, B2, B3]);
2185-
// *I-- = [B1[n], B2[n], B3[n]];
2186-
// *I-- = [B1[n-1], B2[n-1], B3[n-1]];
2187-
// *I-- = [B1[n-2], B2[n-2], B3[n-2]];
2188-
// ...
2189-
class LockstepReverseIterator {
2190-
ArrayRef<BasicBlock*> Blocks;
2191-
SmallVector<Instruction*,4> Insts;
2192-
bool Fail;
2193-
2194-
public:
2195-
LockstepReverseIterator(ArrayRef<BasicBlock*> Blocks) : Blocks(Blocks) {
2196-
reset();
2197-
}
2198-
2199-
void reset() {
2200-
Fail = false;
2201-
Insts.clear();
2202-
for (auto *BB : Blocks) {
2203-
Instruction *Inst = BB->getTerminator();
2204-
for (Inst = Inst->getPrevNode(); Inst && isa<DbgInfoIntrinsic>(Inst);)
2205-
Inst = Inst->getPrevNode();
2206-
if (!Inst) {
2207-
// Block wasn't big enough.
2208-
Fail = true;
2209-
return;
2210-
}
2211-
Insts.push_back(Inst);
2212-
}
2213-
}
2214-
2215-
bool isValid() const {
2216-
return !Fail;
2217-
}
2218-
2219-
void operator--() {
2220-
if (Fail)
2221-
return;
2222-
for (auto *&Inst : Insts) {
2223-
for (Inst = Inst->getPrevNode(); Inst && isa<DbgInfoIntrinsic>(Inst);)
2224-
Inst = Inst->getPrevNode();
2225-
// Already at beginning of block.
2226-
if (!Inst) {
2227-
Fail = true;
2228-
return;
2229-
}
2230-
}
2231-
}
2232-
2233-
void operator++() {
2234-
if (Fail)
2235-
return;
2236-
for (auto *&Inst : Insts) {
2237-
for (Inst = Inst->getNextNode(); Inst && isa<DbgInfoIntrinsic>(Inst);)
2238-
Inst = Inst->getNextNode();
2239-
// Already at end of block.
2240-
if (!Inst) {
2241-
Fail = true;
2242-
return;
2243-
}
2244-
}
2245-
}
2246-
2247-
ArrayRef<Instruction*> operator * () const {
2248-
return Insts;
2249-
}
2250-
};
2251-
2252-
} // end anonymous namespace
2253-
22542254
/// Check whether BB's predecessors end with unconditional branches. If it is
22552255
/// true, sink any common code from the predecessors to BB.
22562256
static bool sinkCommonCodeFromPredecessors(BasicBlock *BB,

0 commit comments

Comments
 (0)