From 0f90b7cb09509822bac7d434cf117ca452700759 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sun, 24 Oct 2021 23:33:10 -0700 Subject: [PATCH] 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 Maintainer: Gabe Black Tested-by: kokoro --- src/cpu/checker/cpu_impl.hh | 6 ++---- src/cpu/simple/base.cc | 4 +--- src/cpu/static_inst.cc | 10 ++++++++++ src/cpu/static_inst.hh | 1 + 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/cpu/checker/cpu_impl.hh b/src/cpu/checker/cpu_impl.hh index 83dbf6bb94..b1571450d0 100644 --- a/src/cpu/checker/cpu_impl.hh +++ b/src/cpu/checker/cpu_impl.hh @@ -74,10 +74,8 @@ Checker::advancePC(const Fault &fault) if (curStaticInst) { if (curStaticInst->isLastMicroop()) curMacroStaticInst = nullStaticInstPtr; - std::unique_ptr 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 48809b5a61..7067f209b9 100644 --- a/src/cpu/simple/base.cc +++ b/src/cpu/simple/base.cc @@ -474,9 +474,7 @@ BaseSimpleCPU::advancePC(const Fault &fault) if (curStaticInst) { if (curStaticInst->isLastMicroop()) curMacroStaticInst = nullStaticInstPtr; - std::unique_ptr 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 63a8a7ae7b..17b01324b7 100644 --- a/src/cpu/static_inst.cc +++ b/src/cpu/static_inst.cc @@ -30,6 +30,8 @@ #include +#include "cpu/thread_context.hh" + namespace gem5 { @@ -82,4 +84,12 @@ StaticInst::printFlags(std::ostream &outs, } } +void +StaticInst::advancePC(ThreadContext *tc) const +{ + std::unique_ptr 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 1213eeb797..3e6357b34e 100644 --- a/src/cpu/static_inst.hh +++ b/src/cpu/static_inst.hh @@ -320,6 +320,7 @@ class StaticInst : public RefCounted, public StaticInstFlags } virtual void advancePC(PCStateBase &pc_state) const = 0; + virtual void advancePC(ThreadContext *tc) const; virtual std::unique_ptr buildRetPC(const PCStateBase &cur_pc, const PCStateBase &call_pc) const