1 //===-- LatencyBenchmarkRunner.cpp ------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "LatencyBenchmarkRunner.h"
12 #include "BenchmarkRunner.h"
17 LatencyBenchmarkRunner::LatencyBenchmarkRunner(const LLVMState
&State
,
18 InstructionBenchmark::ModeE Mode
)
19 : BenchmarkRunner(State
, Mode
) {
20 assert((Mode
== InstructionBenchmark::Latency
||
21 Mode
== InstructionBenchmark::InverseThroughput
) &&
25 LatencyBenchmarkRunner::~LatencyBenchmarkRunner() = default;
27 Expected
<std::vector
<BenchmarkMeasure
>> LatencyBenchmarkRunner::runMeasurements(
28 const FunctionExecutor
&Executor
) const {
29 // Cycle measurements include some overhead from the kernel. Repeat the
30 // measure several times and take the minimum value.
31 constexpr const int NumMeasurements
= 30;
32 int64_t MinValue
= std::numeric_limits
<int64_t>::max();
33 const char *CounterName
= State
.getPfmCounters().CycleCounter
;
34 for (size_t I
= 0; I
< NumMeasurements
; ++I
) {
35 auto ExpectedCounterValue
= Executor
.runAndMeasure(CounterName
);
36 if (!ExpectedCounterValue
)
37 return ExpectedCounterValue
.takeError();
38 if (*ExpectedCounterValue
< MinValue
)
39 MinValue
= *ExpectedCounterValue
;
41 std::vector
<BenchmarkMeasure
> Result
;
43 case InstructionBenchmark::Latency
:
44 Result
= {BenchmarkMeasure::Create("latency", MinValue
)};
46 case InstructionBenchmark::InverseThroughput
:
47 Result
= {BenchmarkMeasure::Create("inverse_throughput", MinValue
)};
52 return std::move(Result
);
55 } // namespace exegesis