cpu: Add a StaticInst::advancePC which takes a ThreadContext.

This will avoid having to create a new heap allocated PCState, since the
instruction will know what type of backing storage to allocate on the
stack for the working copy.

Change-Id: Id208e015f6cb764bf7b13e0faf1677278b7e4641
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/52069
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/src/cpu/checker/cpu_impl.hh b/src/cpu/checker/cpu_impl.hh
index 83dbf6b..b157145 100644
--- a/src/cpu/checker/cpu_impl.hh
+++ b/src/cpu/checker/cpu_impl.hh
@@ -74,10 +74,8 @@
         if (curStaticInst) {
             if (curStaticInst->isLastMicroop())
                 curMacroStaticInst = nullStaticInstPtr;
-            std::unique_ptr<PCStateBase> pc_ptr(thread->pcState().clone());
-            curStaticInst->advancePC(*pc_ptr);
-            thread->pcState(*pc_ptr);
-            DPRINTF(Checker, "Advancing PC to %s.\n", *pc_ptr);
+            curStaticInst->advancePC(thread);
+            DPRINTF(Checker, "Advancing PC to %s.\n", thread->pcState());
         }
     }
 }
diff --git a/src/cpu/simple/base.cc b/src/cpu/simple/base.cc
index 48809b5..7067f20 100644
--- a/src/cpu/simple/base.cc
+++ b/src/cpu/simple/base.cc
@@ -474,9 +474,7 @@
         if (curStaticInst) {
             if (curStaticInst->isLastMicroop())
                 curMacroStaticInst = nullStaticInstPtr;
-            std::unique_ptr<PCStateBase> pc(thread->pcState().clone());
-            curStaticInst->advancePC(*pc);
-            thread->pcState(*pc);
+            curStaticInst->advancePC(thread);
         }
     }
 
diff --git a/src/cpu/static_inst.cc b/src/cpu/static_inst.cc
index 63a8a7a..17b0132 100644
--- a/src/cpu/static_inst.cc
+++ b/src/cpu/static_inst.cc
@@ -30,6 +30,8 @@
 
 #include <iostream>
 
+#include "cpu/thread_context.hh"
+
 namespace gem5
 {
 
@@ -82,4 +84,12 @@
     }
 }
 
+void
+StaticInst::advancePC(ThreadContext *tc) const
+{
+    std::unique_ptr<PCStateBase> pc(tc->pcState().clone());
+    advancePC(*pc);
+    tc->pcState(*pc);
+}
+
 } // namespace gem5
diff --git a/src/cpu/static_inst.hh b/src/cpu/static_inst.hh
index 1213eeb..3e6357b 100644
--- a/src/cpu/static_inst.hh
+++ b/src/cpu/static_inst.hh
@@ -320,6 +320,7 @@
     }
 
     virtual void advancePC(PCStateBase &pc_state) const = 0;
+    virtual void advancePC(ThreadContext *tc) const;
 
     virtual std::unique_ptr<PCStateBase>
     buildRetPC(const PCStateBase &cur_pc, const PCStateBase &call_pc) const