Allow SymbolUserOpInterface operators to be used in RemoveDeadValues Pass (#117405)
[llvm-project.git] / llvm / tools / llvm-exegesis / lib / UopsBenchmarkRunner.cpp
blobd6fb59970b94af2bac332758c5247a5bac4b7f37
1 //===-- UopsBenchmarkRunner.cpp ---------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "UopsBenchmarkRunner.h"
11 #include "Target.h"
13 namespace llvm {
14 namespace exegesis {
16 UopsBenchmarkRunner::~UopsBenchmarkRunner() = default;
18 Expected<std::vector<BenchmarkMeasure>>
19 UopsBenchmarkRunner::runMeasurements(const FunctionExecutor &Executor) const {
20 std::vector<BenchmarkMeasure> Result;
21 const PfmCountersInfo &PCI = State.getPfmCounters();
23 SmallVector<const char *> ValCountersToRun;
24 Error ValCounterErr = getValidationCountersToRun(ValCountersToRun);
25 if (ValCounterErr)
26 return std::move(ValCounterErr);
28 // Uops per port.
29 for (const auto *IssueCounter = PCI.IssueCounters,
30 *IssueCounterEnd = PCI.IssueCounters + PCI.NumIssueCounters;
31 IssueCounter != IssueCounterEnd; ++IssueCounter) {
32 SmallVector<int64_t> ValCounterPortValues(ValCountersToRun.size(), -1);
33 if (!IssueCounter->Counter)
34 continue;
35 auto ExpectedCounterValue = Executor.runAndSample(
36 IssueCounter->Counter, ValCountersToRun, ValCounterPortValues);
37 if (!ExpectedCounterValue)
38 return ExpectedCounterValue.takeError();
40 std::map<ValidationEvent, int64_t> ValidationInfo;
41 for (size_t I = 0; I < ValidationCounters.size(); ++I)
42 ValidationInfo[ValidationCounters[I]] = ValCounterPortValues[I];
44 Result.push_back(BenchmarkMeasure::Create(
45 IssueCounter->ProcResName, (*ExpectedCounterValue)[0], ValidationInfo));
47 // NumMicroOps.
48 if (const char *const UopsCounter = PCI.UopsCounter) {
49 SmallVector<int64_t> ValCounterUopsValues(ValCountersToRun.size(), -1);
50 auto ExpectedCounterValue = Executor.runAndSample(
51 UopsCounter, ValCountersToRun, ValCounterUopsValues);
52 if (!ExpectedCounterValue)
53 return ExpectedCounterValue.takeError();
55 std::map<ValidationEvent, int64_t> ValidationInfo;
56 for (size_t I = 0; I < ValidationCounters.size(); ++I)
57 ValidationInfo[ValidationCounters[I]] = ValCounterUopsValues[I];
59 Result.push_back(BenchmarkMeasure::Create(
60 "NumMicroOps", (*ExpectedCounterValue)[0], ValidationInfo));
62 return std::move(Result);
65 } // namespace exegesis
66 } // namespace llvm