changeset b2071d0eb5f1 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=b2071d0eb5f1
description:
        mem: Modernise MSHR iterators to C++11

        This patch updates the iterators in the MSHR and MSHR queues to use
        C++11 range-based for loops. It also does a bit of additional house
        keeping.

diffstat:

 src/mem/cache/mshr.cc       |  32 ++++++++++++++------------------
 src/mem/cache/mshr.hh       |  21 +++++++++------------
 src/mem/cache/mshr_queue.cc |  30 +++++++-----------------------
 3 files changed, 30 insertions(+), 53 deletions(-)

diffs (224 lines):

diff -r ee0e03afd9da -r b2071d0eb5f1 src/mem/cache/mshr.cc
--- a/src/mem/cache/mshr.cc     Fri Mar 27 04:55:57 2015 -0400
+++ b/src/mem/cache/mshr.cc     Fri Mar 27 04:55:57 2015 -0400
@@ -104,7 +104,7 @@
         }
     }
 
-    push_back(Target(pkt, readyTime, order, source, markPending));
+    emplace_back(Target(pkt, readyTime, order, source, markPending));
 }
 
 
@@ -130,9 +130,8 @@
     if (!hasUpgrade)
         return;
 
-    Iterator end_i = end();
-    for (Iterator i = begin(); i != end_i; ++i) {
-        replaceUpgrade(i->pkt);
+    for (auto& t : *this) {
+        replaceUpgrade(t.pkt);
     }
 
     hasUpgrade = false;
@@ -142,16 +141,15 @@
 void
 MSHR::TargetList::clearDownstreamPending()
 {
-    Iterator end_i = end();
-    for (Iterator i = begin(); i != end_i; ++i) {
-        if (i->markedPending) {
+    for (auto& t : *this) {
+        if (t.markedPending) {
             // Iterate over the SenderState stack and see if we find
             // an MSHR entry. If we find one, clear the
             // downstreamPending flag by calling
             // clearDownstreamPending(). This recursively clears the
             // downstreamPending flag in all caches this packet has
             // passed through.
-            MSHR *mshr = i->pkt->findNextSenderState<MSHR>();
+            MSHR *mshr = t.pkt->findNextSenderState<MSHR>();
             if (mshr != NULL) {
                 mshr->clearDownstreamPending();
             }
@@ -163,9 +161,8 @@
 bool
 MSHR::TargetList::checkFunctional(PacketPtr pkt)
 {
-    Iterator end_i = end();
-    for (Iterator i = begin(); i != end_i; ++i) {
-        if (pkt->checkFunctional(i->pkt)) {
+    for (auto& t : *this) {
+        if (pkt->checkFunctional(t.pkt)) {
             return true;
         }
     }
@@ -175,13 +172,12 @@
 
 
 void
-MSHR::TargetList::
-print(std::ostream &os, int verbosity, const std::string &prefix) const
+MSHR::TargetList::print(std::ostream &os, int verbosity,
+                        const std::string &prefix) const
 {
-    ConstIterator end_i = end();
-    for (ConstIterator i = begin(); i != end_i; ++i) {
+    for (auto& t : *this) {
         const char *s;
-        switch (i->source) {
+        switch (t.source) {
           case Target::FromCPU:
             s = "FromCPU";
             break;
@@ -196,7 +192,7 @@
             break;
         }
         ccprintf(os, "%s%s: ", prefix, s);
-        i->pkt->print(os, verbosity, "");
+        t.pkt->print(os, verbosity, "");
     }
 }
 
@@ -413,7 +409,7 @@
 
 
 void
-MSHR::handleFill(Packet *pkt, CacheBlk *blk)
+MSHR::handleFill(PacketPtr pkt, CacheBlk *blk)
 {
     if (!pkt->sharedAsserted()
         && !(hasPostInvalidate() || hasPostDowngrade())
diff -r ee0e03afd9da -r b2071d0eb5f1 src/mem/cache/mshr.hh
--- a/src/mem/cache/mshr.hh     Fri Mar 27 04:55:57 2015 -0400
+++ b/src/mem/cache/mshr.hh     Fri Mar 27 04:55:57 2015 -0400
@@ -100,13 +100,13 @@
             FromPrefetcher
         };
 
-        Tick recvTime;  //!< Time when request was received (for stats)
-        Tick readyTime; //!< Time when request is ready to be serviced
-        Counter order;  //!< Global order (for memory consistency mgmt)
-        PacketPtr pkt;  //!< Pending request packet.
-        Source source;  //!< Did request come from cpu, memory, or prefetcher?
-        bool markedPending; //!< Did we mark upstream MSHR
-                            //!<  as downstreamPending?
+        const Tick recvTime;  //!< Time when request was received (for stats)
+        const Tick readyTime; //!< Time when request is ready to be serviced
+        const Counter order;  //!< Global order (for memory consistency mgmt)
+        const PacketPtr pkt;  //!< Pending request packet.
+        const Source source;  //!< Request from cpu, memory, or prefetcher?
+        const bool markedPending; //!< Did we mark upstream MSHR
+                                  //!< as downstreamPending?
 
         Target(PacketPtr _pkt, Tick _readyTime, Counter _order,
                Source _source, bool _markedPending)
@@ -116,9 +116,6 @@
     };
 
     class TargetList : public std::list<Target> {
-        /** Target list iterator. */
-        typedef std::list<Target>::iterator Iterator;
-        typedef std::list<Target>::const_iterator ConstIterator;
 
       public:
         bool needsExclusive;
@@ -126,7 +123,7 @@
 
         TargetList();
         void resetFlags() { needsExclusive = hasUpgrade = false; }
-        bool isReset()    { return !needsExclusive && !hasUpgrade; }
+        bool isReset() const { return !needsExclusive && !hasUpgrade; }
         void add(PacketPtr pkt, Tick readyTime, Counter order,
                  Target::Source source, bool markPending);
         void replaceUpgrades();
@@ -285,7 +282,7 @@
 
     bool promoteDeferredTargets();
 
-    void handleFill(Packet *pkt, CacheBlk *blk);
+    void handleFill(PacketPtr pkt, CacheBlk *blk);
 
     bool checkFunctional(PacketPtr pkt);
 
diff -r ee0e03afd9da -r b2071d0eb5f1 src/mem/cache/mshr_queue.cc
--- a/src/mem/cache/mshr_queue.cc       Fri Mar 27 04:55:57 2015 -0400
+++ b/src/mem/cache/mshr_queue.cc       Fri Mar 27 04:55:57 2015 -0400
@@ -68,10 +68,7 @@
 MSHR *
 MSHRQueue::findMatch(Addr blk_addr, bool is_secure) const
 {
-    MSHR::ConstIterator i = allocatedList.begin();
-    MSHR::ConstIterator end = allocatedList.end();
-    for (; i != end; ++i) {
-        MSHR *mshr = *i;
+    for (const auto& mshr : allocatedList) {
         if (mshr->blkAddr == blk_addr && mshr->isSecure == is_secure) {
             return mshr;
         }
@@ -86,10 +83,7 @@
     // Need an empty vector
     assert(matches.empty());
     bool retval = false;
-    MSHR::ConstIterator i = allocatedList.begin();
-    MSHR::ConstIterator end = allocatedList.end();
-    for (; i != end; ++i) {
-        MSHR *mshr = *i;
+    for (const auto& mshr : allocatedList) {
         if (mshr->blkAddr == blk_addr && mshr->isSecure == is_secure) {
             retval = true;
             matches.push_back(mshr);
@@ -103,10 +97,7 @@
 MSHRQueue::checkFunctional(PacketPtr pkt, Addr blk_addr)
 {
     pkt->pushLabel(label);
-    MSHR::ConstIterator i = allocatedList.begin();
-    MSHR::ConstIterator end = allocatedList.end();
-    for (; i != end; ++i) {
-        MSHR *mshr = *i;
+    for (const auto& mshr : allocatedList) {
         if (mshr->blkAddr == blk_addr && mshr->checkFunctional(pkt)) {
             pkt->popLabel();
             return true;
@@ -120,10 +111,7 @@
 MSHR *
 MSHRQueue::findPending(Addr blk_addr, bool is_secure) const
 {
-    MSHR::ConstIterator i = readyList.begin();
-    MSHR::ConstIterator end = readyList.end();
-    for (; i != end; ++i) {
-        MSHR *mshr = *i;
+    for (const auto& mshr : readyList) {
         if (mshr->blkAddr == blk_addr && mshr->isSecure == is_secure) {
             return mshr;
         }
@@ -139,15 +127,13 @@
         return readyList.insert(readyList.end(), mshr);
     }
 
-    MSHR::Iterator i = readyList.begin();
-    MSHR::Iterator end = readyList.end();
-    for (; i != end; ++i) {
+    for (auto i = readyList.begin(); i != readyList.end(); ++i) {
         if ((*i)->readyTime > mshr->readyTime) {
             return readyList.insert(i, mshr);
         }
     }
     assert(false);
-    return end;  // keep stupid compilers happy
+    return readyList.end();  // keep stupid compilers happy
 }
 
 
@@ -251,9 +237,7 @@
 void
 MSHRQueue::squash(int threadNum)
 {
-    MSHR::Iterator i = allocatedList.begin();
-    MSHR::Iterator end = allocatedList.end();
-    for (; i != end;) {
+    for (auto i = allocatedList.begin(); i != allocatedList.end();) {
         MSHR *mshr = *i;
         if (mshr->threadNum == threadNum) {
             while (mshr->hasTargets()) {
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to