@@ -1747,6 +1747,81 @@ static bool isSafeCheapLoadStore(const Instruction *I,
17471747 getLoadStoreAlignment (I) < Value::MaximumAlignment;
17481748}
17491749
1750+ namespace {
1751+
1752+ // LockstepReverseIterator - Iterates through instructions
1753+ // in a set of blocks in reverse order from the first non-terminator.
1754+ // For example (assume all blocks have size n):
1755+ // LockstepReverseIterator I([B1, B2, B3]);
1756+ // *I-- = [B1[n], B2[n], B3[n]];
1757+ // *I-- = [B1[n-1], B2[n-1], B3[n-1]];
1758+ // *I-- = [B1[n-2], B2[n-2], B3[n-2]];
1759+ // ...
1760+ class LockstepReverseIterator {
1761+ ArrayRef<BasicBlock*> Blocks;
1762+ SmallVector<Instruction*,4 > Insts;
1763+ bool Fail;
1764+
1765+ public:
1766+ LockstepReverseIterator (ArrayRef<BasicBlock*> Blocks) : Blocks(Blocks) {
1767+ reset ();
1768+ }
1769+
1770+ void reset () {
1771+ Fail = false ;
1772+ Insts.clear ();
1773+ for (auto *BB : Blocks) {
1774+ Instruction *Inst = BB->getTerminator ();
1775+ for (Inst = Inst->getPrevNode (); Inst && isa<DbgInfoIntrinsic>(Inst);)
1776+ Inst = Inst->getPrevNode ();
1777+ if (!Inst) {
1778+ // Block wasn't big enough.
1779+ Fail = true ;
1780+ return ;
1781+ }
1782+ Insts.push_back (Inst);
1783+ }
1784+ }
1785+
1786+ bool isValid () const {
1787+ return !Fail;
1788+ }
1789+
1790+ void operator --() {
1791+ if (Fail)
1792+ return ;
1793+ for (auto *&Inst : Insts) {
1794+ for (Inst = Inst->getPrevNode (); Inst && isa<DbgInfoIntrinsic>(Inst);)
1795+ Inst = Inst->getPrevNode ();
1796+ // Already at beginning of block.
1797+ if (!Inst) {
1798+ Fail = true ;
1799+ return ;
1800+ }
1801+ }
1802+ }
1803+
1804+ void operator ++() {
1805+ if (Fail)
1806+ return ;
1807+ for (auto *&Inst : Insts) {
1808+ for (Inst = Inst->getNextNode (); Inst && isa<DbgInfoIntrinsic>(Inst);)
1809+ Inst = Inst->getNextNode ();
1810+ // Already at end of block.
1811+ if (!Inst) {
1812+ Fail = true ;
1813+ return ;
1814+ }
1815+ }
1816+ }
1817+
1818+ ArrayRef<Instruction*> operator * () const {
1819+ return Insts;
1820+ }
1821+ };
1822+
1823+ } // end anonymous namespace
1824+
17501825// / Hoist any common code in the successor blocks up into the block. This
17511826// / function guarantees that BB dominates all successors. If EqTermsOnly is
17521827// / given, only perform hoisting in case both blocks only contain a terminator.
@@ -2325,81 +2400,6 @@ static void sinkLastInstruction(ArrayRef<BasicBlock*> Blocks) {
23252400 }
23262401}
23272402
2328- namespace {
2329-
2330- // LockstepReverseIterator - Iterates through instructions
2331- // in a set of blocks in reverse order from the first non-terminator.
2332- // For example (assume all blocks have size n):
2333- // LockstepReverseIterator I([B1, B2, B3]);
2334- // *I-- = [B1[n], B2[n], B3[n]];
2335- // *I-- = [B1[n-1], B2[n-1], B3[n-1]];
2336- // *I-- = [B1[n-2], B2[n-2], B3[n-2]];
2337- // ...
2338- class LockstepReverseIterator {
2339- ArrayRef<BasicBlock*> Blocks;
2340- SmallVector<Instruction*,4 > Insts;
2341- bool Fail;
2342-
2343- public:
2344- LockstepReverseIterator (ArrayRef<BasicBlock*> Blocks) : Blocks(Blocks) {
2345- reset ();
2346- }
2347-
2348- void reset () {
2349- Fail = false ;
2350- Insts.clear ();
2351- for (auto *BB : Blocks) {
2352- Instruction *Inst = BB->getTerminator ();
2353- for (Inst = Inst->getPrevNode (); Inst && isa<DbgInfoIntrinsic>(Inst);)
2354- Inst = Inst->getPrevNode ();
2355- if (!Inst) {
2356- // Block wasn't big enough.
2357- Fail = true ;
2358- return ;
2359- }
2360- Insts.push_back (Inst);
2361- }
2362- }
2363-
2364- bool isValid () const {
2365- return !Fail;
2366- }
2367-
2368- void operator --() {
2369- if (Fail)
2370- return ;
2371- for (auto *&Inst : Insts) {
2372- for (Inst = Inst->getPrevNode (); Inst && isa<DbgInfoIntrinsic>(Inst);)
2373- Inst = Inst->getPrevNode ();
2374- // Already at beginning of block.
2375- if (!Inst) {
2376- Fail = true ;
2377- return ;
2378- }
2379- }
2380- }
2381-
2382- void operator ++() {
2383- if (Fail)
2384- return ;
2385- for (auto *&Inst : Insts) {
2386- for (Inst = Inst->getNextNode (); Inst && isa<DbgInfoIntrinsic>(Inst);)
2387- Inst = Inst->getNextNode ();
2388- // Already at end of block.
2389- if (!Inst) {
2390- Fail = true ;
2391- return ;
2392- }
2393- }
2394- }
2395-
2396- ArrayRef<Instruction*> operator * () const {
2397- return Insts;
2398- }
2399- };
2400-
2401- } // end anonymous namespace
2402-
24032403// / Check whether BB's predecessors end with unconditional branches. If it is
24042404// / true, sink any common code from the predecessors to BB.
24052405static bool sinkCommonCodeFromPredecessors (BasicBlock *BB,
0 commit comments