mem-cache: De-virtualize forEachBlk() in tags

Avoid code duplication by using the anyBlk function
with a lambda that always returns false, which forces
all blocks to be visited.

Change-Id: I25527602535c719f46699677a7f70f3e31157f26
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/70998
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Daniel R. Carvalho
2023-05-27 09:47:56 -03:00
committed by Daniel Carvalho
parent 685a5cd017
commit 77ac6eacd9
8 changed files with 10 additions and 49 deletions

View File

@@ -215,6 +215,15 @@ BaseTags::print()
return str;
}
void
BaseTags::forEachBlk(std::function<void(CacheBlk &)> visitor)
{
anyBlk([visitor](CacheBlk &blk) {
visitor(blk);
return false;
});
}
BaseTags::BaseTagStats::BaseTagStats(BaseTags &_tags)
: statistics::Group(&_tags),
tags(_tags),

View File

@@ -336,7 +336,7 @@ class BaseTags : public ClockedObject
*
* @param visitor Visitor to call on each block.
*/
virtual void forEachBlk(std::function<void(CacheBlk &)> visitor) = 0;
void forEachBlk(std::function<void(CacheBlk &)> visitor);
/**
* Find if any of the blocks satisfies a condition

View File

@@ -233,12 +233,6 @@ class BaseSetAssoc : public BaseTags
return indexingPolicy->regenerateAddr(blk->getTag(), blk);
}
void forEachBlk(std::function<void(CacheBlk &)> visitor) override {
for (CacheBlk& blk : blks) {
visitor(blk);
}
}
bool anyBlk(std::function<bool(CacheBlk &)> visitor) override {
for (CacheBlk& blk : blks) {
if (visitor(blk)) {

View File

@@ -163,14 +163,6 @@ CompressedTags::findVictim(Addr addr, const bool is_secure,
return victim;
}
void
CompressedTags::forEachBlk(std::function<void(CacheBlk &)> visitor)
{
for (CompressionBlk& blk : blks) {
visitor(blk);
}
}
bool
CompressedTags::anyBlk(std::function<bool(CacheBlk &)> visitor)
{

View File

@@ -108,16 +108,6 @@ class CompressedTags : public SectorTags
const std::size_t compressed_size,
std::vector<CacheBlk*>& evict_blks) override;
/**
* Visit each sub-block in the tags and apply a visitor.
*
* The visitor should be a std::function that takes a cache block.
* reference as its parameter.
*
* @param visitor Visitor to call on each block.
*/
void forEachBlk(std::function<void(CacheBlk &)> visitor) override;
/**
* Find if any of the sub-blocks satisfies a condition.
*

View File

@@ -253,12 +253,6 @@ class FALRU : public BaseTags
return blk->getTag();
}
void forEachBlk(std::function<void(CacheBlk &)> visitor) override {
for (int i = 0; i < numBlocks; i++) {
visitor(blks[i]);
}
}
bool anyBlk(std::function<bool(CacheBlk &)> visitor) override {
for (int i = 0; i < numBlocks; i++) {
if (visitor(blks[i])) {

View File

@@ -359,14 +359,6 @@ SectorTags::SectorTagsStats::regStats()
}
}
void
SectorTags::forEachBlk(std::function<void(CacheBlk &)> visitor)
{
for (SectorSubBlk& blk : blks) {
visitor(blk);
}
}
bool
SectorTags::anyBlk(std::function<bool(CacheBlk &)> visitor)
{

View File

@@ -193,16 +193,6 @@ class SectorTags : public BaseTags
*/
Addr regenerateBlkAddr(const CacheBlk* blk) const override;
/**
* Visit each sub-block in the tags and apply a visitor.
*
* The visitor should be a std::function that takes a cache block.
* reference as its parameter.
*
* @param visitor Visitor to call on each block.
*/
void forEachBlk(std::function<void(CacheBlk &)> visitor) override;
/**
* Find if any of the sub-blocks satisfies a condition.
*