blob: 4362df86df678a3a5a479ea73c94e4bd67313794 [file] [log] [blame]
Clement Courbetac74acd2018-04-04 11:37:06 +00001//===-- BenchmarkResult.h ---------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// Defines classes to represent measurements and serialize/deserialize them to
12// Yaml.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H
17#define LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H
18
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/YAMLTraits.h"
Clement Courbetae8ae5dc2018-05-24 12:41:02 +000021#include <limits>
Clement Courbetac74acd2018-04-04 11:37:06 +000022#include <string>
23#include <vector>
24
25namespace exegesis {
26
Clement Courbeta66bfaa42018-05-15 13:07:05 +000027struct InstructionBenchmarkKey {
28 // The LLVM opcode name.
29 std::string OpcodeName;
30 // The benchmark mode.
31 std::string Mode;
32 // An opaque configuration, that can be used to separate several benchmarks of
33 // the same instruction under different configurations.
34 std::string Config;
Clement Courbetac74acd2018-04-04 11:37:06 +000035};
36
37struct BenchmarkMeasure {
38 std::string Key;
39 double Value;
40 std::string DebugString;
41};
42
43// The result of an instruction benchmark.
44struct InstructionBenchmark {
Clement Courbeta66bfaa42018-05-15 13:07:05 +000045 InstructionBenchmarkKey Key;
Clement Courbetac74acd2018-04-04 11:37:06 +000046 std::string CpuName;
47 std::string LLVMTriple;
Clement Courbet8fb6e402018-04-04 12:01:46 +000048 int NumRepetitions = 0;
Clement Courbetac74acd2018-04-04 11:37:06 +000049 std::vector<BenchmarkMeasure> Measurements;
50 std::string Error;
Clement Courbeta66bfaa42018-05-15 13:07:05 +000051 std::string Info;
Clement Courbetac74acd2018-04-04 11:37:06 +000052
53 static InstructionBenchmark readYamlOrDie(llvm::StringRef Filename);
Clement Courbet0e69e2d2018-05-17 10:52:18 +000054 static std::vector<InstructionBenchmark>
Clement Courbetac74acd2018-04-04 11:37:06 +000055
Clement Courbet0e69e2d2018-05-17 10:52:18 +000056 // Read functions.
57 readYamlsOrDie(llvm::StringRef Filename);
58 void readYamlFrom(llvm::StringRef InputContent);
59
60 // Write functions, non-const because of YAML traits.
61 void writeYamlTo(llvm::raw_ostream &S);
Clement Courbetac74acd2018-04-04 11:37:06 +000062 void writeYamlOrDie(const llvm::StringRef Filename);
63};
64
Clement Courbetae8ae5dc2018-05-24 12:41:02 +000065//------------------------------------------------------------------------------
66// Utilities to work with Benchmark measures.
67
68// A class that measures stats over benchmark measures.
69class BenchmarkMeasureStats {
70public:
71 void push(const BenchmarkMeasure &BM);
72
73 double avg() const {
74 assert(NumValues);
75 return SumValues / NumValues;
76 }
77 double min() const { return MinValue; }
78 double max() const { return MaxValue; }
79
80private:
81 std::string Key;
82 double SumValues = 0.0;
83 int NumValues = 0;
84 double MaxValue = std::numeric_limits<double>::min();
85 double MinValue = std::numeric_limits<double>::max();
86};
87
Clement Courbetac74acd2018-04-04 11:37:06 +000088} // namespace exegesis
89
90#endif // LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H