[ARM] Add support for MVE pre and post inc loads and stores
[llvm-core.git] / tools / llvm-exegesis / lib / BenchmarkResult.h
blobe54e8c2a8dac9b3f21510cc9b767909359a67634
1 //===-- BenchmarkResult.h ---------------------------------------*- 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 /// \file
10 /// Defines classes to represent measurements and serialize/deserialize them to
11 // Yaml.
12 ///
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H
16 #define LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H
18 #include "BenchmarkCode.h"
19 #include "LlvmState.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/MC/MCInstBuilder.h"
24 #include "llvm/Support/YAMLTraits.h"
25 #include <limits>
26 #include <string>
27 #include <unordered_map>
28 #include <vector>
30 namespace llvm {
31 namespace exegesis {
33 struct InstructionBenchmarkKey {
34 // The LLVM opcode name.
35 std::vector<llvm::MCInst> Instructions;
36 // The initial values of the registers.
37 std::vector<RegisterValue> RegisterInitialValues;
38 // An opaque configuration, that can be used to separate several benchmarks of
39 // the same instruction under different configurations.
40 std::string Config;
43 struct BenchmarkMeasure {
44 // A helper to create an unscaled BenchmarkMeasure.
45 static BenchmarkMeasure Create(std::string Key, double Value) {
46 return {Key, Value, Value};
48 std::string Key;
49 // This is the per-instruction value, i.e. measured quantity scaled per
50 // instruction.
51 double PerInstructionValue;
52 // This is the per-snippet value, i.e. measured quantity for one repetition of
53 // the whole snippet.
54 double PerSnippetValue;
57 // The result of an instruction benchmark.
58 struct InstructionBenchmark {
59 InstructionBenchmarkKey Key;
60 enum ModeE { Unknown, Latency, Uops, InverseThroughput };
61 ModeE Mode;
62 std::string CpuName;
63 std::string LLVMTriple;
64 // Which instruction is being benchmarked here?
65 const llvm::MCInst &keyInstruction() const { return Key.Instructions[0]; }
66 // The number of instructions inside the repeated snippet. For example, if a
67 // snippet of 3 instructions is repeated 4 times, this is 12.
68 int NumRepetitions = 0;
69 // Note that measurements are per instruction.
70 std::vector<BenchmarkMeasure> Measurements;
71 std::string Error;
72 std::string Info;
73 std::vector<uint8_t> AssembledSnippet;
75 // Read functions.
76 static llvm::Expected<InstructionBenchmark>
77 readYaml(const LLVMState &State, llvm::StringRef Filename);
79 static llvm::Expected<std::vector<InstructionBenchmark>>
80 readYamls(const LLVMState &State, llvm::StringRef Filename);
82 llvm::Error readYamlFrom(const LLVMState &State,
83 llvm::StringRef InputContent);
85 // Write functions, non-const because of YAML traits.
86 llvm::Error writeYamlTo(const LLVMState &State, llvm::raw_ostream &S);
88 llvm::Error writeYaml(const LLVMState &State, const llvm::StringRef Filename);
91 //------------------------------------------------------------------------------
92 // Utilities to work with Benchmark measures.
94 // A class that measures stats over benchmark measures.
95 class PerInstructionStats {
96 public:
97 void push(const BenchmarkMeasure &BM);
99 double avg() const {
100 assert(NumValues);
101 return SumValues / NumValues;
103 double min() const { return MinValue; }
104 double max() const { return MaxValue; }
106 const std::string &key() const { return Key; }
108 private:
109 std::string Key;
110 double SumValues = 0.0;
111 int NumValues = 0;
112 double MaxValue = std::numeric_limits<double>::min();
113 double MinValue = std::numeric_limits<double>::max();
116 } // namespace exegesis
117 } // namespace llvm
119 #endif // LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H