blob: 715ad5884c17bb72f86453b18057e56a57a0773f [file] [log] [blame]
Clement Courbetac74acd2018-04-04 11:37:06 +00001//===-- 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
19#include "BenchmarkResult.h"
20#include "InMemoryAssembler.h"
21#include "LlvmState.h"
22#include "llvm/MC/MCInst.h"
23#include "llvm/Support/Error.h"
24#include <vector>
25
26namespace exegesis {
27
28// Common code for all benchmark modes.
29class BenchmarkRunner {
30public:
31 // Subtargets can disable running benchmarks for some instructions by
32 // returning an error here.
33 class InstructionFilter {
34 public:
35 virtual ~InstructionFilter();
36
37 virtual llvm::Error shouldRun(const LLVMState &State,
38 unsigned Opcode) const {
39 return llvm::ErrorSuccess();
40 }
41 };
42
43 virtual ~BenchmarkRunner();
44
45 InstructionBenchmark run(const LLVMState &State, unsigned Opcode,
46 unsigned NumRepetitions,
47 const InstructionFilter &Filter) const;
48
49private:
50 virtual const char *getDisplayName() const = 0;
51
52 virtual llvm::Expected<std::vector<llvm::MCInst>>
53 createCode(const LLVMState &State, unsigned OpcodeIndex,
54 unsigned NumRepetitions,
55 const JitFunctionContext &Context) const = 0;
56
57 virtual std::vector<BenchmarkMeasure>
58 runMeasurements(const LLVMState &State, const JitFunction &Function,
59 unsigned NumRepetitions) const = 0;
60};
61
62} // namespace exegesis
63
64#endif // LLVM_TOOLS_LLVM_EXEGESIS_BENCHMARKRUNNER_H