67 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "UopsBenchmarkRunner.h"10 11#include "Target.h"12 13namespace llvm {14namespace exegesis {15 16UopsBenchmarkRunner::~UopsBenchmarkRunner() = default;17 18Expected<std::vector<BenchmarkMeasure>>19UopsBenchmarkRunner::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 IssueCounter->Counter, ValCountersToRun, 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(BenchmarkMeasure::Create(45 IssueCounter->ProcResName, (*ExpectedCounterValue)[0], 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 UopsCounter, ValCountersToRun, 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(BenchmarkMeasure::Create(60 "NumMicroOps", (*ExpectedCounterValue)[0], ValidationInfo));61 }62 return std::move(Result);63}64 65} // namespace exegesis66} // namespace llvm67