From 0c50a0b4fe3956f9d2e08e75d47c9cbd79bf0268 Mon Sep 17 00:00:00 2001 From: Rekai Gonzalez-Alberquilla Date: Mon, 6 Feb 2017 11:10:06 +0000 Subject: cpu: Fix the usage of const DynInstPtr Summary: Usage of const DynInstPtr& when possible and introduction of move operators to RefCountingPtr. In many places, scoped references to dynamic instructions do a copy of the DynInstPtr when a reference would do. This is detrimental to performance. On top of that, in case there is a need for reference tracking for debugging, the redundant copies make the process much more painful than it already is. Also, from the theoretical point of view, a function/method that defines a convenience name to access an instruction should not be considered an owner of the data, i.e., doing a copy and not a reference is not justified. On a related topic, C++11 introduces move semantics, and those are useful when, for example, there is a class modelling a HW structure that contains a list, and has a getHeadOfList function, to prevent doing a copy to an internal variable -> update pointer, remove from the list -> update pointer, return value making a copy to the assined variable -> update pointer, destroy the returned value -> update pointer. Change-Id: I3bb46c20ef23b6873b469fd22befb251ac44d2f6 Signed-off-by: Giacomo Gabrielli Reviewed-on: https://gem5-review.googlesource.com/c/13105 Reviewed-by: Andreas Sandberg Reviewed-by: Jason Lowe-Power Maintainer: Andreas Sandberg Maintainer: Jason Lowe-Power --- src/cpu/checker/cpu.hh | 15 ++++++++------- src/cpu/checker/cpu_impl.hh | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'src/cpu/checker') diff --git a/src/cpu/checker/cpu.hh b/src/cpu/checker/cpu.hh index bee72253e..cb87f622a 100644 --- a/src/cpu/checker/cpu.hh +++ b/src/cpu/checker/cpu.hh @@ -397,7 +397,8 @@ class CheckerCPU : public BaseCPU, public ExecContext setVecElemResult(val); } - bool readPredicate() override { return thread->readPredicate(); } + bool readPredicate() const override { return thread->readPredicate(); } + void setPredicate(bool val) override { thread->setPredicate(val); @@ -572,18 +573,18 @@ class Checker : public CheckerCPU void advancePC(const Fault &fault); - void verify(DynInstPtr &inst); + void verify(const DynInstPtr &inst); - void validateInst(DynInstPtr &inst); - void validateExecution(DynInstPtr &inst); + void validateInst(const DynInstPtr &inst); + void validateExecution(const DynInstPtr &inst); void validateState(); - void copyResult(DynInstPtr &inst, const InstResult& mismatch_val, + void copyResult(const DynInstPtr &inst, const InstResult& mismatch_val, int start_idx); void handlePendingInt(); private: - void handleError(DynInstPtr &inst) + void handleError(const DynInstPtr &inst) { if (exitOnError) { dumpAndExit(inst); @@ -592,7 +593,7 @@ class Checker : public CheckerCPU } } - void dumpAndExit(DynInstPtr &inst); + void dumpAndExit(const DynInstPtr &inst); bool updateThisCycle; diff --git a/src/cpu/checker/cpu_impl.hh b/src/cpu/checker/cpu_impl.hh index 57282cd13..4fa59564a 100644 --- a/src/cpu/checker/cpu_impl.hh +++ b/src/cpu/checker/cpu_impl.hh @@ -124,7 +124,7 @@ Checker::handlePendingInt() template void -Checker::verify(DynInstPtr &completed_inst) +Checker::verify(const DynInstPtr &completed_inst) { DynInstPtr inst; @@ -456,7 +456,7 @@ Checker::takeOverFrom(BaseCPU *oldCPU) template void -Checker::validateInst(DynInstPtr &inst) +Checker::validateInst(const DynInstPtr &inst) { if (inst->instAddr() != thread->instAddr()) { warn("%lli: PCs do not match! Inst: %s, checker: %s", @@ -477,7 +477,7 @@ Checker::validateInst(DynInstPtr &inst) template void -Checker::validateExecution(DynInstPtr &inst) +Checker::validateExecution(const DynInstPtr &inst) { InstResult checker_val; InstResult inst_val; @@ -595,8 +595,8 @@ Checker::validateState() template void -Checker::copyResult(DynInstPtr &inst, const InstResult& mismatch_val, - int start_idx) +Checker::copyResult(const DynInstPtr &inst, + const InstResult& mismatch_val, int start_idx) { // We've already popped one dest off the queue, // so do the fix-up then start with the next dest reg; @@ -672,7 +672,7 @@ Checker::copyResult(DynInstPtr &inst, const InstResult& mismatch_val, template void -Checker::dumpAndExit(DynInstPtr &inst) +Checker::dumpAndExit(const DynInstPtr &inst) { cprintf("Error detected, instruction information:\n"); cprintf("PC:%s, nextPC:%#x\n[sn:%lli]\n[tid:%i]\n" -- cgit v1.2.3