From 4ed7341abb5fc2f13cacced32dd877dbc1ebab78 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 3 Dec 2021 18:39:05 -0800 Subject: [PATCH] cpu-minor: Ensure the pc in BranchData is always set. Change the type passed to updateBranchData in execute to be a reference, and replace the nullptr being passed in from Execute::evaluate() with the current thread's pc. We could use any generic PC instead which might be slightly faster, but there is likely not a significant difference and this is a lot easier. Change-Id: I306ca53b33997f76217c61123e5922df612005f9 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/53584 Maintainer: Gabe Black Reviewed-by: Bobby Bruce Tested-by: kokoro --- src/cpu/minor/execute.cc | 13 +++++++------ src/cpu/minor/execute.hh | 2 +- src/cpu/minor/fetch2.cc | 2 +- src/cpu/minor/pipe_data.hh | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cpu/minor/execute.cc b/src/cpu/minor/execute.cc index 8de0c560e6..c09f3be741 100644 --- a/src/cpu/minor/execute.cc +++ b/src/cpu/minor/execute.cc @@ -296,14 +296,14 @@ Execute::tryToBranch(MinorDynInstPtr inst, Fault fault, BranchData &branch) reason = BranchData::NoBranch; } - updateBranchData(inst->id.threadId, reason, inst, target.get(), branch); + updateBranchData(inst->id.threadId, reason, inst, *target, branch); } void Execute::updateBranchData( ThreadID tid, BranchData::Reason reason, - MinorDynInstPtr inst, const PCStateBase *target, + MinorDynInstPtr inst, const PCStateBase &target, BranchData &branch) { if (reason != BranchData::NoBranch) { @@ -443,7 +443,7 @@ Execute::takeInterrupt(ThreadID thread_id, BranchData &branch) /* Assume that an interrupt *must* cause a branch. Assert this? */ updateBranchData(thread_id, BranchData::Interrupt, - MinorDynInst::bubble(), &cpu.getContext(thread_id)->pcState(), + MinorDynInst::bubble(), cpu.getContext(thread_id)->pcState(), branch); } @@ -1032,7 +1032,7 @@ Execute::commitInst(MinorDynInstPtr inst, bool early_memory_issue, cpu.stats.numFetchSuspends++; updateBranchData(thread_id, BranchData::SuspendThread, inst, - &resume_pc, branch); + resume_pc, branch); } } @@ -1140,7 +1140,7 @@ Execute::commit(ThreadID thread_id, bool only_commit_microops, bool discard, /* Branch as there was a change in PC */ updateBranchData(thread_id, BranchData::UnpredictedBranch, - MinorDynInst::bubble(), &thread->pcState(), branch); + MinorDynInst::bubble(), thread->pcState(), branch); } else if (mem_response && num_mem_refs_committed < memoryCommitLimit) { @@ -1495,7 +1495,8 @@ Execute::evaluate() * the bag */ if (commit_info.drainState == DrainHaltFetch) { updateBranchData(commit_tid, BranchData::HaltFetch, - MinorDynInst::bubble(), nullptr, branch); + MinorDynInst::bubble(), + cpu.getContext(commit_tid)->pcState(), branch); cpu.wakeupOnEvent(Pipeline::ExecuteStageId); setDrainState(commit_tid, DrainAllInsts); diff --git a/src/cpu/minor/execute.hh b/src/cpu/minor/execute.hh index 21720bbb46..9d184f7428 100644 --- a/src/cpu/minor/execute.hh +++ b/src/cpu/minor/execute.hh @@ -232,7 +232,7 @@ class Execute : public Named /** Actually create a branch to communicate to Fetch1/Fetch2 and, * if that is a stream-changing branch update the streamSeqNum */ void updateBranchData(ThreadID tid, BranchData::Reason reason, - MinorDynInstPtr inst, const PCStateBase *target, BranchData &branch); + MinorDynInstPtr inst, const PCStateBase &target, BranchData &branch); /** Handle extracting mem ref responses from the memory queues and * completing the associated instructions. diff --git a/src/cpu/minor/fetch2.cc b/src/cpu/minor/fetch2.cc index 82648d0069..44789e2d2f 100644 --- a/src/cpu/minor/fetch2.cc +++ b/src/cpu/minor/fetch2.cc @@ -223,7 +223,7 @@ Fetch2::predictBranch(MinorDynInstPtr inst, BranchData &branch) BranchData new_branch = BranchData(BranchData::BranchPrediction, inst->id.threadId, inst->id.streamSeqNum, thread.predictionSeqNum + 1, - inst->predictedTarget.get(), inst); + *inst->predictedTarget, inst); /* Mark with a new prediction number by the stream number of the * instruction causing the prediction */ diff --git a/src/cpu/minor/pipe_data.hh b/src/cpu/minor/pipe_data.hh index b736ea9762..97651b4b46 100644 --- a/src/cpu/minor/pipe_data.hh +++ b/src/cpu/minor/pipe_data.hh @@ -130,7 +130,7 @@ class BranchData /* : public ReportIF, public BubbleIF */ BranchData(Reason reason_, ThreadID thread_id, InstSeqNum new_stream_seq_num, InstSeqNum new_prediction_seq_num, - const PCStateBase *_target, MinorDynInstPtr inst_) : + const PCStateBase &_target, MinorDynInstPtr inst_) : reason(reason_), threadId(thread_id), newStreamSeqNum(new_stream_seq_num), newPredictionSeqNum(new_prediction_seq_num),