1 //===-- BenchmarkResult.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Defines classes to represent measurements and serialize/deserialize them to
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H
17 #define LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H
19 #include "BenchmarkCode.h"
20 #include "LlvmState.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/MC/MCInst.h"
24 #include "llvm/MC/MCInstBuilder.h"
25 #include "llvm/Support/YAMLTraits.h"
28 #include <unordered_map>
34 struct InstructionBenchmarkKey
{
35 // The LLVM opcode name.
36 std::vector
<llvm::MCInst
> Instructions
;
37 // The initial values of the registers.
38 std::vector
<RegisterValue
> RegisterInitialValues
;
39 // An opaque configuration, that can be used to separate several benchmarks of
40 // the same instruction under different configurations.
44 struct BenchmarkMeasure
{
45 // A helper to create an unscaled BenchmarkMeasure.
46 static BenchmarkMeasure
Create(std::string Key
, double Value
) {
47 return {Key
, Value
, Value
};
50 // This is the per-instruction value, i.e. measured quantity scaled per
52 double PerInstructionValue
;
53 // This is the per-snippet value, i.e. measured quantity for one repetition of
55 double PerSnippetValue
;
58 // The result of an instruction benchmark.
59 struct InstructionBenchmark
{
60 InstructionBenchmarkKey Key
;
61 enum ModeE
{ Unknown
, Latency
, Uops
};
64 std::string LLVMTriple
;
65 // The number of instructions inside the repeated snippet. For example, if a
66 // snippet of 3 instructions is repeated 4 times, this is 12.
67 int NumRepetitions
= 0;
68 // Note that measurements are per instruction.
69 std::vector
<BenchmarkMeasure
> Measurements
;
72 std::vector
<uint8_t> AssembledSnippet
;
75 static llvm::Expected
<InstructionBenchmark
>
76 readYaml(const LLVMState
&State
, llvm::StringRef Filename
);
78 static llvm::Expected
<std::vector
<InstructionBenchmark
>>
79 readYamls(const LLVMState
&State
, llvm::StringRef Filename
);
81 void readYamlFrom(const LLVMState
&State
, llvm::StringRef InputContent
);
83 // Write functions, non-const because of YAML traits.
84 void writeYamlTo(const LLVMState
&State
, llvm::raw_ostream
&S
);
86 llvm::Error
writeYaml(const LLVMState
&State
, const llvm::StringRef Filename
);
89 //------------------------------------------------------------------------------
90 // Utilities to work with Benchmark measures.
92 // A class that measures stats over benchmark measures.
93 class PerInstructionStats
{
95 void push(const BenchmarkMeasure
&BM
);
99 return SumValues
/ NumValues
;
101 double min() const { return MinValue
; }
102 double max() const { return MaxValue
; }
104 const std::string
&key() const { return Key
; }
108 double SumValues
= 0.0;
110 double MaxValue
= std::numeric_limits
<double>::min();
111 double MinValue
= std::numeric_limits
<double>::max();
114 } // namespace exegesis
117 #endif // LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H