From 0196a8780f2d3a378f0fd3b86a6e6b6590ca02de Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Sat, 30 Dec 2023 15:37:56 -0800 Subject: [PATCH 1/2] [llvm-exegesis] Remove unused Counter::read method This method was simply a wrapper around readOrError. All users within the llvm-exegesis code base should have been processing an actual error rather than using the wrapper. This patch removes the wrapper and rewrites the users (just 1) to use the readOrError method. --- llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 6 +++++- llvm/tools/llvm-exegesis/lib/PerfHelper.cpp | 13 ------------- llvm/tools/llvm-exegesis/lib/PerfHelper.h | 3 --- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index 1ee59a86ebbdc..c57fce970b213 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -356,7 +356,11 @@ class SubProcessFunctionExecutorImpl if (ChildExitCode == 0) { // The child exited succesfully, read counter values and return // success - CounterValues[0] = Counter->read(); + auto CounterValueOrErr = Counter->readOrError(); + if (!CounterValueOrErr) + return CounterValueOrErr.takeError(); + CounterValues.swap(*CounterValueOrErr); + return Error::success(); } // The child exited, but not successfully diff --git a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp index 3ff1745e9e062..314de1ec32366 100644 --- a/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp +++ b/llvm/tools/llvm-exegesis/lib/PerfHelper.cpp @@ -148,17 +148,6 @@ void Counter::stop() { ioctl(FileDescriptor, PERF_EVENT_IOC_DISABLE, 0); } -int64_t Counter::read() const { - auto ValueOrError = readOrError(); - if (ValueOrError) { - if (!ValueOrError.get().empty()) - return ValueOrError.get()[0]; - errs() << "Counter has no reading\n"; - } else - errs() << ValueOrError.takeError() << "\n"; - return -1; -} - llvm::Expected> Counter::readOrError(StringRef /*unused*/) const { int64_t Count = 0; @@ -187,8 +176,6 @@ void Counter::start() {} void Counter::stop() {} -int64_t Counter::read() const { return 42; } - llvm::Expected> Counter::readOrError(StringRef /*unused*/) const { if (IsDummyEvent) { diff --git a/llvm/tools/llvm-exegesis/lib/PerfHelper.h b/llvm/tools/llvm-exegesis/lib/PerfHelper.h index a50974f0a67be..894aac1f197ed 100644 --- a/llvm/tools/llvm-exegesis/lib/PerfHelper.h +++ b/llvm/tools/llvm-exegesis/lib/PerfHelper.h @@ -95,9 +95,6 @@ class Counter { /// Stops the measurement of the event. void stop(); - /// Returns the current value of the counter or -1 if it cannot be read. - int64_t read() const; - /// Returns the current value of the counter or error if it cannot be read. /// FunctionBytes: The benchmark function being executed. /// This is used to filter out the measurements to ensure they are only From 34797cd6c9c85045f563a74e756a1e2a7d77b8a3 Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Wed, 3 Jan 2024 11:38:00 -0800 Subject: [PATCH 2/2] Switch swap to move --- llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp index c57fce970b213..59d1dc4f86feb 100644 --- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -359,7 +359,7 @@ class SubProcessFunctionExecutorImpl auto CounterValueOrErr = Counter->readOrError(); if (!CounterValueOrErr) return CounterValueOrErr.takeError(); - CounterValues.swap(*CounterValueOrErr); + CounterValues = std::move(*CounterValueOrErr); return Error::success(); }