Bug 1031682 - Add OperandIter::settle to skip instructions with no operands. r=nbp
authorCaio Lima <ticaiolima@gmail.com>
Wed, 02 Jul 2014 08:52:00 +0200
changeset 192163 af2c7776626540dc8eed65c78d7eda056a2c3018
parent 192079 35e4a142417cade44c2aab85946a141e43a99c53
child 192164 f1bacafe789c9d30ae8e5f49f31822ed942217cc
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersnbp
bugs1031682
milestone33.0a1
Bug 1031682 - Add OperandIter::settle to skip instructions with no operands. r=nbp
js/src/jit/LIR.cpp
js/src/jit/LIR.h
js/src/jit/shared/CodeGenerator-shared.cpp
js/src/jit/shared/Lowering-shared.cpp
--- a/js/src/jit/LIR.cpp
+++ b/js/src/jit/LIR.cpp
@@ -176,21 +176,18 @@ void
 LBlock::dump()
 {
     dump(stderr);
 }
 
 static size_t
 TotalOperandCount(LRecoverInfo *recoverInfo)
 {
-    LRecoverInfo::OperandIter it(recoverInfo->begin());
-    LRecoverInfo::OperandIter end(recoverInfo->end());
     size_t accum = 0;
-
-    for (; it != end; ++it) {
+    for (LRecoverInfo::OperandIter it(recoverInfo); !it; ++it) {
         if (!it->isRecoveredOnBailout())
             accum++;
     }
     return accum;
 }
 
 LRecoverInfo::LRecoverInfo(TempAllocator &alloc)
   : instructions_(alloc),
--- a/js/src/jit/LIR.h
+++ b/js/src/jit/LIR.h
@@ -960,41 +960,54 @@ class LRecoverInfo : public TempObject
     size_t numInstructions() const {
         return instructions_.length();
     }
 
     class OperandIter
     {
       private:
         MNode **it_;
+        MNode **end_;
         size_t op_;
 
       public:
-        explicit OperandIter(MNode **it)
-          : it_(it), op_(0)
-        { }
+        explicit OperandIter(LRecoverInfo *recoverInfo)
+          : it_(recoverInfo->begin()), end_(recoverInfo->end()), op_(0)
+        {
+            settle();
+        }
+
+        void settle() {
+            while ((*it_)->numOperands() == 0) {
+                ++it_;
+                op_ = 0;
+            }
+        }
 
         MDefinition *operator *() {
             return (*it_)->getOperand(op_);
         }
         MDefinition *operator ->() {
             return (*it_)->getOperand(op_);
         }
 
         OperandIter &operator ++() {
             ++op_;
             if (op_ == (*it_)->numOperands()) {
                 op_ = 0;
                 ++it_;
             }
+            if (!*this)
+                settle();
+
             return *this;
         }
 
-        bool operator !=(const OperandIter &where) const {
-            return it_ != where.it_ || op_ != where.op_;
+        operator bool() const {
+            return it_ == end_;
         }
 
 #ifdef DEBUG
         bool canOptimizeOutIfUnused();
 #endif
     };
 };
 
--- a/js/src/jit/shared/CodeGenerator-shared.cpp
+++ b/js/src/jit/shared/CodeGenerator-shared.cpp
@@ -312,19 +312,17 @@ CodeGeneratorShared::encode(LSnapshot *s
             if (ins->mirRaw()->trackedPc())
                 pcOpcode = *ins->mirRaw()->trackedPc();
         }
     }
     snapshots_.trackSnapshot(pcOpcode, mirOpcode, mirId, lirOpcode, lirId);
 #endif
 
     uint32_t allocIndex = 0;
-    LRecoverInfo::OperandIter it(recoverInfo->begin());
-    LRecoverInfo::OperandIter end(recoverInfo->end());
-    for (; it != end; ++it) {
+    for (LRecoverInfo::OperandIter it(recoverInfo); !it; ++it) {
         DebugOnly<uint32_t> allocWritten = snapshots_.allocWritten();
         if (!encodeAllocation(snapshot, *it, &allocIndex))
             return false;
         MOZ_ASSERT(allocWritten + 1 == snapshots_.allocWritten());
     }
 
     MOZ_ASSERT(allocIndex == snapshot->numSlots());
     snapshots_.endSnapshot();
--- a/js/src/jit/shared/Lowering-shared.cpp
+++ b/js/src/jit/shared/Lowering-shared.cpp
@@ -101,19 +101,17 @@ LIRGeneratorShared::buildSnapshot(LInstr
     if (!recoverInfo)
         return nullptr;
 
     LSnapshot *snapshot = LSnapshot::New(gen, recoverInfo, kind);
     if (!snapshot)
         return nullptr;
 
     size_t index = 0;
-    LRecoverInfo::OperandIter it(recoverInfo->begin());
-    LRecoverInfo::OperandIter end(recoverInfo->end());
-    for (; it != end; ++it) {
+    for (LRecoverInfo::OperandIter it(recoverInfo); !it; ++it) {
         // Check that optimized out operands are in eliminable slots.
         MOZ_ASSERT(it.canOptimizeOutIfUnused());
 
         MDefinition *ins = *it;
 
         if (ins->isRecoveredOnBailout())
             continue;
 
@@ -161,19 +159,17 @@ LIRGeneratorShared::buildSnapshot(LInstr
     if (!recoverInfo)
         return nullptr;
 
     LSnapshot *snapshot = LSnapshot::New(gen, recoverInfo, kind);
     if (!snapshot)
         return nullptr;
 
     size_t index = 0;
-    LRecoverInfo::OperandIter it(recoverInfo->begin());
-    LRecoverInfo::OperandIter end(recoverInfo->end());
-    for (; it != end; ++it) {
+    for (LRecoverInfo::OperandIter it(recoverInfo); !it; ++it) {
         // Check that optimized out operands are in eliminable slots.
         MOZ_ASSERT(it.canOptimizeOutIfUnused());
 
         MDefinition *def = *it;
 
         if (def->isRecoveredOnBailout())
             continue;