mem-cache: Fix set and way of sub-entries

Set and way of sub-entries were not being set previously.
They must be set after the sub-blocks have been assigned
to the main block.

Change-Id: I7b6921b8437b29c472d691cd78cf20f2bb6c7e07
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/19669
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/src/mem/cache/replacement_policies/replaceable_entry.hh b/src/mem/cache/replacement_policies/replaceable_entry.hh
index bf54e22..dffa4cf 100644
--- a/src/mem/cache/replacement_policies/replaceable_entry.hh
+++ b/src/mem/cache/replacement_policies/replaceable_entry.hh
@@ -76,7 +76,9 @@
      * @param set The set of this entry.
      * @param way The way of this entry.
      */
-    void setPosition(const uint32_t set, const uint32_t way) {
+    virtual void
+    setPosition(const uint32_t set, const uint32_t way)
+    {
         _set = set;
         _way = way;
     }
diff --git a/src/mem/cache/tags/compressed_tags.cc b/src/mem/cache/tags/compressed_tags.cc
index 0896a1b..1394be8 100644
--- a/src/mem/cache/tags/compressed_tags.cc
+++ b/src/mem/cache/tags/compressed_tags.cc
@@ -67,9 +67,6 @@
         // allocation conditions
         superblock->setBlkSize(blkSize);
 
-        // Link block to indexing policy
-        indexingPolicy->setEntry(superblock, superblock_index);
-
         // Associate a replacement data entry to the block
         superblock->replacementData = replacementPolicy->instantiateEntry();
 
@@ -97,6 +94,9 @@
             // Update block index
             ++blk_index;
         }
+
+        // Link block to indexing policy
+        indexingPolicy->setEntry(superblock, superblock_index);
     }
 }
 
diff --git a/src/mem/cache/tags/sector_blk.cc b/src/mem/cache/tags/sector_blk.cc
index 93b1961..7e4468d 100644
--- a/src/mem/cache/tags/sector_blk.cc
+++ b/src/mem/cache/tags/sector_blk.cc
@@ -167,3 +167,12 @@
 {
     _secureBit = true;
 }
+
+void
+SectorBlk::setPosition(const uint32_t set, const uint32_t way)
+{
+    ReplaceableEntry::setPosition(set, way);
+    for (auto& blk : blks) {
+        blk->setPosition(set, way);
+    }
+}
diff --git a/src/mem/cache/tags/sector_blk.hh b/src/mem/cache/tags/sector_blk.hh
index ca0d9a8..a30fb81 100644
--- a/src/mem/cache/tags/sector_blk.hh
+++ b/src/mem/cache/tags/sector_blk.hh
@@ -214,6 +214,14 @@
      * Set secure bit.
      */
     void setSecure();
+
+    /**
+     * Sets the position of the sub-entries, besides its own.
+     *
+     * @param set The set of this entry and sub-entries.
+     * @param way The way of this entry and sub-entries.
+     */
+    void setPosition(const uint32_t set, const uint32_t way) override;
 };
 
 #endif //__MEM_CACHE_TAGS_SECTOR_BLK_HH__
diff --git a/src/mem/cache/tags/sector_tags.cc b/src/mem/cache/tags/sector_tags.cc
index 535badb..1098885 100644
--- a/src/mem/cache/tags/sector_tags.cc
+++ b/src/mem/cache/tags/sector_tags.cc
@@ -77,9 +77,6 @@
         // Locate next cache sector
         SectorBlk* sec_blk = &secBlks[sec_blk_index];
 
-        // Link block to indexing policy
-        indexingPolicy->setEntry(sec_blk, sec_blk_index);
-
         // Associate a replacement data entry to the sector
         sec_blk->replacementData = replacementPolicy->instantiateEntry();
 
@@ -107,6 +104,9 @@
             // Update block index
             ++blk_index;
         }
+
+        // Link block to indexing policy
+        indexingPolicy->setEntry(sec_blk, sec_blk_index);
     }
 }