mem-cache: Allow inheriting from DitionaryCompressor's comp data
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Fri, 8 Nov 2019 13:21:21 +0000 (14:21 +0100)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Mon, 31 Aug 2020 17:45:43 +0000 (17:45 +0000)
Previously either the compression data was the one declared within
DictionaryCompressor, or the derived class would have to override
the compress() to use a derived compression data.

With this change, the instantiation can be overridden, and thus
any derived class can choose the compression data pointer type
they need to use.

Change-Id: I387936265a3de6785a6096c7a6bd21774202b1c7
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33378
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/mem/cache/compressors/dictionary_compressor.hh
src/mem/cache/compressors/dictionary_compressor_impl.hh

index b5e9e673ebb20897c85eb238cbdedf67e849b5b0..a0bdf4d43328a3fdeb977794adaab090babf3e91 100644 (file)
@@ -221,6 +221,14 @@ class DictionaryCompressor : public BaseDictionaryCompressor
      */
     virtual void addToDictionary(const DictionaryEntry data) = 0;
 
+    /**
+     * Instantiate a compression data of the sub-class compressor.
+     *
+     * @return The new compression data entry.
+     */
+    virtual std::unique_ptr<DictionaryCompressor::CompData>
+    instantiateDictionaryCompData() const;
+
     /**
      * Apply compression.
      *
index 6b6e5fbc6eb7a491145341c2d4b4fe69104301c7..b157216671b6201c6d89dcd80ede2f2337de7ab3 100644 (file)
@@ -79,6 +79,13 @@ DictionaryCompressor<T>::resetDictionary()
     std::fill(dictionary.begin(), dictionary.end(), toDictionaryEntry(0));
 }
 
+template <typename T>
+std::unique_ptr<typename DictionaryCompressor<T>::CompData>
+DictionaryCompressor<T>::instantiateDictionaryCompData() const
+{
+    return std::unique_ptr<DictionaryCompressor<T>::CompData>(new CompData());
+}
+
 template <typename T>
 std::unique_ptr<typename DictionaryCompressor<T>::Pattern>
 DictionaryCompressor<T>::compressValue(const T data)
@@ -119,7 +126,7 @@ std::unique_ptr<Base::CompressionData>
 DictionaryCompressor<T>::compress(const uint64_t* data)
 {
     std::unique_ptr<Base::CompressionData> comp_data =
-        std::unique_ptr<CompData>(new CompData());
+        instantiateDictionaryCompData();
 
     // Reset dictionary
     resetDictionary();