[llvm-exegesis] Improve Register Setup.
[llvm-core.git] / tools / llvm-exegesis / lib / SnippetGenerator.h
blob2a412ba95e6b4fdfdf9c8743e7f8357062f7a53f
1 //===-- SnippetGenerator.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 SnippetGenerator class for generating code that allows
12 /// measuring a certain property of instructions (e.g. latency).
13 ///
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H
17 #define LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H
19 #include "Assembler.h"
20 #include "BenchmarkCode.h"
21 #include "LlvmState.h"
22 #include "MCInstrDescView.h"
23 #include "RegisterAliasing.h"
24 #include "llvm/MC/MCInst.h"
25 #include "llvm/Support/Error.h"
26 #include <cstdlib>
27 #include <memory>
28 #include <vector>
30 namespace exegesis {
32 // A class representing failures that happened during Benchmark, they are used
33 // to report informations to the user.
34 class SnippetGeneratorFailure : public llvm::StringError {
35 public:
36 SnippetGeneratorFailure(const llvm::Twine &S);
39 // Common code for all benchmark modes.
40 class SnippetGenerator {
41 public:
42 explicit SnippetGenerator(const LLVMState &State);
44 virtual ~SnippetGenerator();
46 // Calls generateCodeTemplate and expands it into one or more BenchmarkCode.
47 llvm::Expected<std::vector<BenchmarkCode>>
48 generateConfigurations(unsigned Opcode) const;
50 // Given a snippet, computes which registers the setup code needs to define.
51 std::vector<RegisterValue> computeRegisterInitialValues(
52 const std::vector<InstructionBuilder> &Snippet) const;
54 protected:
55 const LLVMState &State;
56 const RegisterAliasingTrackerCache RATC;
58 // Generates a single code template that has a self-dependency.
59 llvm::Expected<CodeTemplate>
60 generateSelfAliasingCodeTemplate(const Instruction &Instr) const;
61 // Generates a single code template without assignment constraints.
62 llvm::Expected<CodeTemplate>
63 generateUnconstrainedCodeTemplate(const Instruction &Instr,
64 llvm::StringRef Msg) const;
66 private:
67 // API to be implemented by subclasses.
68 virtual llvm::Expected<CodeTemplate>
69 generateCodeTemplate(unsigned Opcode) const = 0;
72 } // namespace exegesis
74 #endif // LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H