Tom Rollet has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/68297?usp=email )

Change subject: cpu-o3: remove RefCounted from DynInst
......................................................................

cpu-o3: remove RefCounted from DynInst

RefCounted class can be replaced with shared_ptr.
This will add minimal overhead than can be mitigated by
handling more carefully shared_ptr.

Change-Id: I5947b06420ff842b6a6a27056bb073194d46da9d
---
M src/cpu/o3/dyn_inst.cc
M src/cpu/o3/dyn_inst.hh
M src/cpu/o3/dyn_inst_ptr.hh
M src/cpu/o3/fetch.cc
M src/cpu/o3/lsq_unit.hh
5 files changed, 29 insertions(+), 11 deletions(-)



diff --git a/src/cpu/o3/dyn_inst.cc b/src/cpu/o3/dyn_inst.cc
index 0b9a900..fd6d26f 100644
--- a/src/cpu/o3/dyn_inst.cc
+++ b/src/cpu/o3/dyn_inst.cc
@@ -404,7 +404,7 @@
 {
     assert(byte_enable.size() == size);
     return cpu->pushRequest(
-        dynamic_cast<DynInstPtr::PtrType>(this),
+        this->shared_from_this(),
         /* ld */ true, nullptr, size, addr, flags, nullptr, nullptr,
         byte_enable);
 }
@@ -414,7 +414,7 @@
 {
     const unsigned int size = 8;
     return cpu->pushRequest(
-            dynamic_cast<DynInstPtr::PtrType>(this),
+            this->shared_from_this(),
             /* ld */ true, nullptr, size, 0x0ul, flags, nullptr, nullptr,
             std::vector<bool>(size, true));
 }
@@ -426,7 +426,7 @@
 {
     assert(byte_enable.size() == size);
     return cpu->pushRequest(
-        dynamic_cast<DynInstPtr::PtrType>(this),
+        this->shared_from_this(),
         /* st */ false, data, size, addr, flags, res, nullptr,
         byte_enable);
 }
@@ -441,7 +441,7 @@
     // Atomic memory requests need to carry their `amo_op` fields to cache/
     // memory
     return cpu->pushRequest(
-            dynamic_cast<DynInstPtr::PtrType>(this),
+            this->shared_from_this(),
             /* atomic */ false, nullptr, size, addr, flags, nullptr,
             std::move(amo_op), std::vector<bool>(size, true));
 }
diff --git a/src/cpu/o3/dyn_inst.hh b/src/cpu/o3/dyn_inst.hh
index ab165bb..f5c766b 100644
--- a/src/cpu/o3/dyn_inst.hh
+++ b/src/cpu/o3/dyn_inst.hh
@@ -46,9 +46,9 @@
 #include <array>
 #include <deque>
 #include <list>
+#include <memory>
 #include <string>

-#include "base/refcnt.hh"
 #include "base/trace.hh"
 #include "cpu/checker/cpu.hh"
 #include "cpu/exec_context.hh"
@@ -72,7 +72,8 @@
 namespace o3
 {

-class DynInst : public ExecContext, public RefCounted
+class DynInst : public ExecContext,
+    public std::enable_shared_from_this<DynInst>
 {
   private:
     DynInst(const StaticInstPtr &staticInst, const StaticInstPtr &macroop,
diff --git a/src/cpu/o3/dyn_inst_ptr.hh b/src/cpu/o3/dyn_inst_ptr.hh
index 38a38c3..cc393c6 100644
--- a/src/cpu/o3/dyn_inst_ptr.hh
+++ b/src/cpu/o3/dyn_inst_ptr.hh
@@ -42,6 +42,8 @@
 #ifndef __CPU_O3_DYN_INST_PTR_HH__
 #define __CPU_O3_DYN_INST_PTR_HH__

+#include <memory>
+
 #include "base/refcnt.hh"

 namespace gem5
@@ -52,8 +54,8 @@

 class DynInst;

-using DynInstPtr = RefCountingPtr<DynInst>;
-using DynInstConstPtr = RefCountingPtr<const DynInst>;
+using DynInstPtr = std::shared_ptr<DynInst>;
+using DynInstConstPtr = std::shared_ptr<const DynInst>;

 } // namespace o3
 } // namespace gem5
diff --git a/src/cpu/o3/fetch.cc b/src/cpu/o3/fetch.cc
index d3cdd2c..4a39920 100644
--- a/src/cpu/o3/fetch.cc
+++ b/src/cpu/o3/fetch.cc
@@ -45,6 +45,7 @@
 #include <cstring>
 #include <list>
 #include <map>
+#include <memory>
 #include <queue>

 #include "arch/generic/tlb.hh"
@@ -1051,8 +1052,9 @@
     arrays.numDests = staticInst->numDestRegs();

     // Create a new DynInst from the instruction fetched.
-    DynInstPtr instruction = new (arrays) DynInst(
-            arrays, staticInst, curMacroop, this_pc, next_pc, seq, cpu);
+    DynInstPtr instruction = std::shared_ptr<DynInst>(new (arrays) DynInst(
+            arrays, staticInst, curMacroop, this_pc, next_pc, seq, cpu));
+
     instruction->setTid(tid);

     instruction->setThreadState(cpu->thread[tid]);
diff --git a/src/cpu/o3/lsq_unit.hh b/src/cpu/o3/lsq_unit.hh
index b807179..9fd5b8d 100644
--- a/src/cpu/o3/lsq_unit.hh
+++ b/src/cpu/o3/lsq_unit.hh
@@ -287,7 +287,7 @@
/** Returns if there is a memory ordering violation. Value is reset upon
      * call to getMemDepViolator().
      */
-    bool violation() { return memDepViolator; }
+    bool violation() { return memDepViolator != nullptr; }

     /** Returns the memory ordering violator. */
     DynInstPtr getMemDepViolator();

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/68297?usp=email To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I5947b06420ff842b6a6a27056bb073194d46da9d
Gerrit-Change-Number: 68297
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Rollet <tom.rol...@huawei.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org

Reply via email to