Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 1 | //===-- BenchmarkRunner.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 the abstract BenchmarkRunner class for measuring a certain execution |
| 12 | /// property of instructions (e.g. latency). |
| 13 | /// |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRUNNER_H |
| 17 | #define LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRUNNER_H |
| 18 | |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 19 | #include "Assembler.h" |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 20 | #include "BenchmarkResult.h" |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 21 | #include "LlvmState.h" |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 22 | #include "RegisterAliasing.h" |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCInst.h" |
| 24 | #include "llvm/Support/Error.h" |
| 25 | #include <vector> |
| 26 | |
| 27 | namespace exegesis { |
| 28 | |
Guillaume Chatelet | 7b852cd | 2018-06-07 08:11:54 +0000 | [diff] [blame^] | 29 | // A collection of instructions that are to be assembled, executed and measured. |
| 30 | struct BenchmarkConfiguration { |
| 31 | // This code is run before the Snippet is iterated. Since it is part of the |
| 32 | // measurement it should be as short as possible. It is usually used to setup |
| 33 | // the content of the Registers. |
| 34 | std::vector<llvm::MCInst> SnippetSetup; |
| 35 | |
| 36 | // The sequence of instructions that are to be repeated. |
| 37 | std::vector<llvm::MCInst> Snippet; |
| 38 | }; |
| 39 | |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 40 | // Common code for all benchmark modes. |
| 41 | class BenchmarkRunner { |
| 42 | public: |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 43 | explicit BenchmarkRunner(const LLVMState &State); |
| 44 | |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 45 | // Subtargets can disable running benchmarks for some instructions by |
| 46 | // returning an error here. |
| 47 | class InstructionFilter { |
| 48 | public: |
| 49 | virtual ~InstructionFilter(); |
| 50 | |
| 51 | virtual llvm::Error shouldRun(const LLVMState &State, |
| 52 | unsigned Opcode) const { |
| 53 | return llvm::ErrorSuccess(); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | virtual ~BenchmarkRunner(); |
| 58 | |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 59 | InstructionBenchmark run(unsigned Opcode, const InstructionFilter &Filter, |
| 60 | unsigned NumRepetitions); |
| 61 | |
| 62 | protected: |
| 63 | const LLVMState &State; |
| 64 | const llvm::MCInstrInfo &MCInstrInfo; |
| 65 | const llvm::MCRegisterInfo &MCRegisterInfo; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 66 | |
| 67 | private: |
Clement Courbet | 62b34fa | 2018-06-06 09:42:36 +0000 | [diff] [blame] | 68 | virtual InstructionBenchmark::ModeE getMode() const = 0; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 69 | |
Guillaume Chatelet | 7b852cd | 2018-06-07 08:11:54 +0000 | [diff] [blame^] | 70 | virtual llvm::Expected<BenchmarkConfiguration> |
| 71 | createConfiguration(RegisterAliasingTrackerCache &RATC, unsigned Opcode, |
| 72 | llvm::raw_ostream &Debug) const = 0; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 73 | |
| 74 | virtual std::vector<BenchmarkMeasure> |
Clement Courbet | 0e69e2d | 2018-05-17 10:52:18 +0000 | [diff] [blame] | 75 | runMeasurements(const ExecutableFunction &EF, |
| 76 | const unsigned NumRepetitions) const = 0; |
| 77 | |
| 78 | llvm::Expected<std::string> |
| 79 | writeObjectFile(llvm::ArrayRef<llvm::MCInst> Code) const; |
| 80 | |
| 81 | RegisterAliasingTrackerCache RATC; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | } // namespace exegesis |
| 85 | |
| 86 | #endif // LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRUNNER_H |