Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 1 | //===-- 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 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame^] | 19 | #include "LlvmState.h" |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringMap.h" |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringRef.h" |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCInst.h" |
| 23 | #include "llvm/MC/MCInstBuilder.h" |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 24 | #include "llvm/Support/YAMLTraits.h" |
Clement Courbet | ae8ae5dc | 2018-05-24 12:41:02 +0000 | [diff] [blame] | 25 | #include <limits> |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 26 | #include <string> |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 27 | #include <unordered_map> |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 28 | #include <vector> |
| 29 | |
| 30 | namespace exegesis { |
| 31 | |
Clement Courbet | a66bfaa4 | 2018-05-15 13:07:05 +0000 | [diff] [blame] | 32 | struct InstructionBenchmarkKey { |
| 33 | // The LLVM opcode name. |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 34 | std::vector<llvm::MCInst> Instructions; |
Clement Courbet | a66bfaa4 | 2018-05-15 13:07:05 +0000 | [diff] [blame] | 35 | // An opaque configuration, that can be used to separate several benchmarks of |
| 36 | // the same instruction under different configurations. |
| 37 | std::string Config; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | struct BenchmarkMeasure { |
| 41 | std::string Key; |
| 42 | double Value; |
| 43 | std::string DebugString; |
| 44 | }; |
| 45 | |
| 46 | // The result of an instruction benchmark. |
| 47 | struct InstructionBenchmark { |
Clement Courbet | a66bfaa4 | 2018-05-15 13:07:05 +0000 | [diff] [blame] | 48 | InstructionBenchmarkKey Key; |
Clement Courbet | 62b34fa | 2018-06-06 09:42:36 +0000 | [diff] [blame] | 49 | enum ModeE { Unknown, Latency, Uops }; |
| 50 | ModeE Mode; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 51 | std::string CpuName; |
| 52 | std::string LLVMTriple; |
Clement Courbet | f64007f | 2018-06-15 09:27:12 +0000 | [diff] [blame] | 53 | // The number of instructions inside the repeated snippet. For example, if a |
| 54 | // snippet of 3 instructions is repeated 4 times, this is 12. |
Clement Courbet | 8fb6e40 | 2018-04-04 12:01:46 +0000 | [diff] [blame] | 55 | int NumRepetitions = 0; |
Clement Courbet | f64007f | 2018-06-15 09:27:12 +0000 | [diff] [blame] | 56 | // Note that measurements are per instruction. |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 57 | std::vector<BenchmarkMeasure> Measurements; |
| 58 | std::string Error; |
Clement Courbet | a66bfaa4 | 2018-05-15 13:07:05 +0000 | [diff] [blame] | 59 | std::string Info; |
Clement Courbet | 4273e1e | 2018-06-15 07:30:45 +0000 | [diff] [blame] | 60 | std::vector<uint8_t> AssembledSnippet; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 61 | |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 62 | // Read functions. |
Guillaume Chatelet | 8c91d4c | 2018-06-07 07:51:16 +0000 | [diff] [blame] | 63 | static llvm::Expected<InstructionBenchmark> |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame^] | 64 | readYaml(const LLVMState &State, llvm::StringRef Filename); |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 65 | |
Guillaume Chatelet | 8c91d4c | 2018-06-07 07:51:16 +0000 | [diff] [blame] | 66 | static llvm::Expected<std::vector<InstructionBenchmark>> |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame^] | 67 | readYamls(const LLVMState &State, llvm::StringRef Filename); |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 68 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame^] | 69 | void readYamlFrom(const LLVMState &State, llvm::StringRef InputContent); |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 70 | |
| 71 | // Write functions, non-const because of YAML traits. |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame^] | 72 | void writeYamlTo(const LLVMState &State, llvm::raw_ostream &S); |
Clement Courbet | 53d35d2 | 2018-06-05 10:56:19 +0000 | [diff] [blame] | 73 | |
Guillaume Chatelet | 55ad087 | 2018-09-25 12:18:08 +0000 | [diff] [blame^] | 74 | llvm::Error writeYaml(const LLVMState &State, const llvm::StringRef Filename); |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
Clement Courbet | ae8ae5dc | 2018-05-24 12:41:02 +0000 | [diff] [blame] | 77 | //------------------------------------------------------------------------------ |
| 78 | // Utilities to work with Benchmark measures. |
| 79 | |
| 80 | // A class that measures stats over benchmark measures. |
| 81 | class BenchmarkMeasureStats { |
| 82 | public: |
| 83 | void push(const BenchmarkMeasure &BM); |
| 84 | |
| 85 | double avg() const { |
| 86 | assert(NumValues); |
| 87 | return SumValues / NumValues; |
| 88 | } |
| 89 | double min() const { return MinValue; } |
| 90 | double max() const { return MaxValue; } |
| 91 | |
Clement Courbet | 7228721 | 2018-06-04 11:11:55 +0000 | [diff] [blame] | 92 | const std::string &key() const { return Key; } |
| 93 | |
Clement Courbet | ae8ae5dc | 2018-05-24 12:41:02 +0000 | [diff] [blame] | 94 | private: |
| 95 | std::string Key; |
| 96 | double SumValues = 0.0; |
| 97 | int NumValues = 0; |
| 98 | double MaxValue = std::numeric_limits<double>::min(); |
| 99 | double MinValue = std::numeric_limits<double>::max(); |
| 100 | }; |
| 101 | |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 102 | } // namespace exegesis |
| 103 | |
| 104 | #endif // LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRESULT_H |