mem-cache: Remove Cache dependency from Tags

Tags do not need to be aware of caches.

Change-Id: Ib6a082b74dcd9b2f10852651634b59512732fb2a
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/14296
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
diff --git a/src/mem/cache/base.cc b/src/mem/cache/base.cc
index 980aa91..497f75c 100644
--- a/src/mem/cache/base.cc
+++ b/src/mem/cache/base.cc
@@ -118,7 +118,7 @@
 
     tempBlock = new TempCacheBlk(blkSize);
 
-    tags->tagsInit(this);
+    tags->tagsInit();
     if (prefetcher)
         prefetcher->setCache(this);
 }
diff --git a/src/mem/cache/tags/Tags.py b/src/mem/cache/tags/Tags.py
index b34779e..f2658f4 100644
--- a/src/mem/cache/tags/Tags.py
+++ b/src/mem/cache/tags/Tags.py
@@ -44,6 +44,10 @@
     type = 'BaseTags'
     abstract = True
     cxx_header = "mem/cache/tags/base.hh"
+
+    # Get system to which it belongs
+    system = Param.System(Parent.any, "System we belong to")
+
     # Get the size from the parent (cache)
     size = Param.MemorySize(Parent.size, "capacity in bytes")
 
diff --git a/src/mem/cache/tags/base.cc b/src/mem/cache/tags/base.cc
index 5fbbdc1..7237f18 100644
--- a/src/mem/cache/tags/base.cc
+++ b/src/mem/cache/tags/base.cc
@@ -51,7 +51,6 @@
 #include <cassert>
 
 #include "base/types.hh"
-#include "mem/cache/base.hh"
 #include "mem/cache/replacement_policies/replaceable_entry.hh"
 #include "mem/cache/tags/indexing_policies/base.hh"
 #include "mem/request.hh"
@@ -62,20 +61,13 @@
 BaseTags::BaseTags(const Params *p)
     : ClockedObject(p), blkSize(p->block_size), blkMask(blkSize - 1),
       size(p->size), lookupLatency(p->tag_latency),
-      cache(nullptr), indexingPolicy(p->indexing_policy),
+      system(p->system), indexingPolicy(p->indexing_policy),
       warmupBound((p->warmup_percentage/100.0) * (p->size / p->block_size)),
       warmedUp(false), numBlocks(p->size / p->block_size),
       dataBlks(new uint8_t[p->size]) // Allocate data storage in one big chunk
 {
 }
 
-void
-BaseTags::setCache(BaseCache *_cache)
-{
-    assert(!cache);
-    cache = _cache;
-}
-
 ReplaceableEntry*
 BaseTags::findBlockBySetAndWay(int set, int way) const
 {
@@ -115,7 +107,7 @@
     // Previous block, if existed, has been removed, and now we have
     // to insert the new one
     // Deal with what we are bringing in
-    assert(src_master_ID < cache->system->maxMasters());
+    assert(src_master_ID < system->maxMasters());
     occupancies[src_master_ID]++;
 
     // Insert block with tag, src master id and task id
@@ -243,13 +235,13 @@
         ;
 
     occupancies
-        .init(cache->system->maxMasters())
+        .init(system->maxMasters())
         .name(name() + ".occ_blocks")
         .desc("Average occupied blocks per requestor")
         .flags(nozero | nonan)
         ;
-    for (int i = 0; i < cache->system->maxMasters(); i++) {
-        occupancies.subname(i, cache->system->getMasterName(i));
+    for (int i = 0; i < system->maxMasters(); i++) {
+        occupancies.subname(i, system->getMasterName(i));
     }
 
     avgOccs
@@ -257,8 +249,8 @@
         .desc("Average percentage of cache occupancy")
         .flags(nozero | total)
         ;
-    for (int i = 0; i < cache->system->maxMasters(); i++) {
-        avgOccs.subname(i, cache->system->getMasterName(i));
+    for (int i = 0; i < system->maxMasters(); i++) {
+        avgOccs.subname(i, system->getMasterName(i));
     }
 
     avgOccs = occupancies / Stats::constant(numBlocks);
diff --git a/src/mem/cache/tags/base.hh b/src/mem/cache/tags/base.hh
index 273abf5..840193b 100644
--- a/src/mem/cache/tags/base.hh
+++ b/src/mem/cache/tags/base.hh
@@ -61,7 +61,7 @@
 #include "params/BaseTags.hh"
 #include "sim/clocked_object.hh"
 
-class BaseCache;
+class System;
 class IndexingPolicy;
 class ReplaceableEntry;
 
@@ -80,8 +80,8 @@
     /** The tag lookup latency of the cache. */
     const Cycles lookupLatency;
 
-    /** Pointer to the parent cache. */
-    BaseCache *cache;
+    /** System we are currently operating in. */
+    System *system;
 
     /** Indexing policy */
     BaseIndexingPolicy *indexingPolicy;
@@ -153,13 +153,6 @@
      * @}
      */
 
-    /**
-     * Set the parent cache back pointer.
-     *
-     * @param _cache Pointer to parent cache.
-     */
-    void setCache(BaseCache *_cache);
-
   public:
     typedef BaseTagsParams Params;
     BaseTags(const Params *p);
@@ -170,11 +163,11 @@
     virtual ~BaseTags() {}
 
     /**
-     * Initialize blocks and set the parent cache back pointer.
-     *
-     * @param _cache Pointer to parent cache.
+     * Initialize blocks. Must be overriden by every subclass that uses
+     * a block type different from its parent's, as the current Python
+     * code generation does not allow templates.
      */
-    virtual void tagsInit(BaseCache *_cache) = 0;
+    virtual void tagsInit() = 0;
 
     /**
      * Register local statistics.
diff --git a/src/mem/cache/tags/base_set_assoc.cc b/src/mem/cache/tags/base_set_assoc.cc
index b3b7731..1b53ef0 100644
--- a/src/mem/cache/tags/base_set_assoc.cc
+++ b/src/mem/cache/tags/base_set_assoc.cc
@@ -63,11 +63,8 @@
 }
 
 void
-BaseSetAssoc::tagsInit(BaseCache* cache)
+BaseSetAssoc::tagsInit()
 {
-    // Set parent cache
-    setCache(cache);
-
     // Initialize all blocks
     for (unsigned blk_index = 0; blk_index < numBlocks; blk_index++) {
         // Locate next cache block
diff --git a/src/mem/cache/tags/base_set_assoc.hh b/src/mem/cache/tags/base_set_assoc.hh
index bc98afa..b1fa884 100644
--- a/src/mem/cache/tags/base_set_assoc.hh
+++ b/src/mem/cache/tags/base_set_assoc.hh
@@ -99,11 +99,9 @@
     virtual ~BaseSetAssoc() {};
 
     /**
-     * Initialize blocks and set the parent cache back pointer.
-     *
-     * @param _cache Pointer to parent cache.
+     * Initialize blocks as CacheBlk instances.
      */
-    void tagsInit(BaseCache *_cache) override;
+    void tagsInit() override;
 
     /**
      * This function updates the tags when a block is invalidated. It also
diff --git a/src/mem/cache/tags/fa_lru.cc b/src/mem/cache/tags/fa_lru.cc
index 9648468..b1f9bbc 100644
--- a/src/mem/cache/tags/fa_lru.cc
+++ b/src/mem/cache/tags/fa_lru.cc
@@ -84,11 +84,8 @@
 }
 
 void
-FALRU::tagsInit(BaseCache* cache)
+FALRU::tagsInit()
 {
-    // Set parent cache
-    setCache(cache);
-
     head = &(blks[0]);
     head->prev = nullptr;
     head->next = &(blks[1]);
diff --git a/src/mem/cache/tags/fa_lru.hh b/src/mem/cache/tags/fa_lru.hh
index 1de6de4..0cae1de 100644
--- a/src/mem/cache/tags/fa_lru.hh
+++ b/src/mem/cache/tags/fa_lru.hh
@@ -159,11 +159,9 @@
     ~FALRU();
 
     /**
-     * Initialize blocks and set the parent cache back pointer.
-     *
-     * @param _cache Pointer to parent cache.
+     * Initialize blocks as FALRUBlk instances.
      */
-    void tagsInit(BaseCache *_cache) override;
+    void tagsInit() override;
 
     /**
      * Register the stats for this object.
diff --git a/src/mem/cache/tags/sector_tags.cc b/src/mem/cache/tags/sector_tags.cc
index 02649cc..68440c2 100644
--- a/src/mem/cache/tags/sector_tags.cc
+++ b/src/mem/cache/tags/sector_tags.cc
@@ -64,11 +64,8 @@
 }
 
 void
-SectorTags::tagsInit(BaseCache* cache)
+SectorTags::tagsInit()
 {
-    // Set parent cache
-    setCache(cache);
-
     // Initialize all blocks
     unsigned blk_index = 0;       // index into blks array
     for (unsigned sec_blk_index = 0; sec_blk_index < numSectors;
diff --git a/src/mem/cache/tags/sector_tags.hh b/src/mem/cache/tags/sector_tags.hh
index f9d47f3..e3c0fa4 100644
--- a/src/mem/cache/tags/sector_tags.hh
+++ b/src/mem/cache/tags/sector_tags.hh
@@ -101,11 +101,9 @@
     virtual ~SectorTags() {};
 
     /**
-     * Initialize blocks and set the parent cache back pointer.
-     *
-     * @param _cache Pointer to parent cache.
+     * Initialize blocks as SectorBlk and SectorSubBlk instances.
      */
-    void tagsInit(BaseCache *_cache) override;
+    void tagsInit() override;
 
     /**
      * This function updates the tags when a block is invalidated but does