| 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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "UopsBenchmarkRunner.h" |
| 10 | |
| 11 | #include "Target.h" |
| 12 | |
| 13 | namespace llvm { |
| 14 | namespace exegesis { |
| 15 | |
| 16 | UopsBenchmarkRunner::~UopsBenchmarkRunner() = default; |
| 17 | |
| 18 | Expected<std::vector<BenchmarkMeasure>> |
| 19 | UopsBenchmarkRunner::runMeasurements(const FunctionExecutor &Executor) const { |
| 20 | std::vector<BenchmarkMeasure> Result; |
| 21 | const PfmCountersInfo &PCI = State.getPfmCounters(); |
| 22 | |
| 23 | SmallVector<const char *> ValCountersToRun; |
| 24 | Error ValCounterErr = getValidationCountersToRun(ValCountersToRun); |
| 25 | if (ValCounterErr) |
| 26 | return std::move(ValCounterErr); |
| 27 | |
| 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 | Counters: IssueCounter->Counter, ValidationCounters: ValCountersToRun, ValidationCounterValues&: ValCounterPortValues); |
| 37 | if (!ExpectedCounterValue) |
| 38 | return ExpectedCounterValue.takeError(); |
| 39 | |
| 40 | std::map<ValidationEvent, int64_t> ValidationInfo; |
| 41 | for (size_t I = 0; I < ValidationCounters.size(); ++I) |
| 42 | ValidationInfo[ValidationCounters[I]] = ValCounterPortValues[I]; |
| 43 | |
| 44 | Result.push_back(x: BenchmarkMeasure::Create( |
| 45 | Key: IssueCounter->ProcResName, Value: (*ExpectedCounterValue)[0], ValCounters: ValidationInfo)); |
| 46 | } |
| 47 | // NumMicroOps. |
| 48 | if (const char *const UopsCounter = PCI.UopsCounter) { |
| 49 | SmallVector<int64_t> ValCounterUopsValues(ValCountersToRun.size(), -1); |
| 50 | auto ExpectedCounterValue = Executor.runAndSample( |
| 51 | Counters: UopsCounter, ValidationCounters: ValCountersToRun, ValidationCounterValues&: ValCounterUopsValues); |
| 52 | if (!ExpectedCounterValue) |
| 53 | return ExpectedCounterValue.takeError(); |
| 54 | |
| 55 | std::map<ValidationEvent, int64_t> ValidationInfo; |
| 56 | for (size_t I = 0; I < ValidationCounters.size(); ++I) |
| 57 | ValidationInfo[ValidationCounters[I]] = ValCounterUopsValues[I]; |
| 58 | |
| 59 | Result.push_back(x: BenchmarkMeasure::Create( |
| 60 | Key: "NumMicroOps" , Value: (*ExpectedCounterValue)[0], ValCounters: ValidationInfo)); |
| 61 | } |
| 62 | return std::move(Result); |
| 63 | } |
| 64 | |
| 65 | } // namespace exegesis |
| 66 | } // namespace llvm |
| 67 | |