Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H |
| 17 | #define LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H |
| 18 | |
| 19 | #include "Assembler.h" |
| 20 | #include "BenchmarkCode.h" |
Guillaume Chatelet | 7f8d310 | 2018-09-26 11:57:24 +0000 | [diff] [blame^] | 21 | #include "CodeTemplate.h" |
Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 22 | #include "LlvmState.h" |
| 23 | #include "MCInstrDescView.h" |
| 24 | #include "RegisterAliasing.h" |
| 25 | #include "llvm/MC/MCInst.h" |
| 26 | #include "llvm/Support/Error.h" |
| 27 | #include <cstdlib> |
| 28 | #include <memory> |
| 29 | #include <vector> |
| 30 | |
| 31 | namespace exegesis { |
| 32 | |
| 33 | // A class representing failures that happened during Benchmark, they are used |
| 34 | // to report informations to the user. |
| 35 | class SnippetGeneratorFailure : public llvm::StringError { |
| 36 | public: |
| 37 | SnippetGeneratorFailure(const llvm::Twine &S); |
| 38 | }; |
| 39 | |
| 40 | // Common code for all benchmark modes. |
| 41 | class SnippetGenerator { |
| 42 | public: |
| 43 | explicit SnippetGenerator(const LLVMState &State); |
| 44 | |
| 45 | virtual ~SnippetGenerator(); |
| 46 | |
| 47 | // Calls generateCodeTemplate and expands it into one or more BenchmarkCode. |
| 48 | llvm::Expected<std::vector<BenchmarkCode>> |
| 49 | generateConfigurations(unsigned Opcode) const; |
| 50 | |
| 51 | // Given a snippet, computes which registers the setup code needs to define. |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame] | 52 | std::vector<RegisterValue> computeRegisterInitialValues( |
| 53 | const std::vector<InstructionBuilder> &Snippet) const; |
Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 54 | |
| 55 | protected: |
| 56 | const LLVMState &State; |
| 57 | const RegisterAliasingTrackerCache RATC; |
| 58 | |
| 59 | // Generates a single code template that has a self-dependency. |
| 60 | llvm::Expected<CodeTemplate> |
| 61 | generateSelfAliasingCodeTemplate(const Instruction &Instr) const; |
| 62 | // Generates a single code template without assignment constraints. |
| 63 | llvm::Expected<CodeTemplate> |
| 64 | generateUnconstrainedCodeTemplate(const Instruction &Instr, |
| 65 | llvm::StringRef Msg) const; |
| 66 | |
| 67 | private: |
| 68 | // API to be implemented by subclasses. |
| 69 | virtual llvm::Expected<CodeTemplate> |
| 70 | generateCodeTemplate(unsigned Opcode) const = 0; |
| 71 | }; |
| 72 | |
| 73 | } // namespace exegesis |
| 74 | |
| 75 | #endif // LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H |