diff options
| author | Clement Courbet <courbet@google.com> | 2018-09-13 07:40:53 +0000 |
|---|---|---|
| committer | Clement Courbet <courbet@google.com> | 2018-09-13 07:40:53 +0000 |
| commit | d939f6d01396201d1b8fb5dba652e9528276e79e (patch) | |
| tree | a6a1ce6223ee509273ef8b3f6d7c9a080ee6034a /llvm/tools/llvm-exegesis/lib/SnippetGenerator.h | |
| parent | 58c3dee3b3cdf103680d80b61167dda9612d3e0d (diff) | |
| download | bcm5719-llvm-d939f6d01396201d1b8fb5dba652e9528276e79e.tar.gz bcm5719-llvm-d939f6d01396201d1b8fb5dba652e9528276e79e.zip | |
[llvm-exegesis][NFC] Split BenchmarkRunner class
Summary:
The snippet-generation part goes to the SnippetGenerator class.
This will allow benchmarking arbitrary code (see PR38437).
Reviewers: gchatelet
Subscribers: mgorny, tschuett, llvm-commits
Differential Revision: https://reviews.llvm.org/D51979
llvm-svn: 342117
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/SnippetGenerator.h')
| -rw-r--r-- | llvm/tools/llvm-exegesis/lib/SnippetGenerator.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/SnippetGenerator.h b/llvm/tools/llvm-exegesis/lib/SnippetGenerator.h new file mode 100644 index 00000000000..ced8ebc5a28 --- /dev/null +++ b/llvm/tools/llvm-exegesis/lib/SnippetGenerator.h @@ -0,0 +1,74 @@ +//===-- SnippetGenerator.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// Defines the abstract SnippetGenerator class for generating code that allows +/// measuring a certain property of instructions (e.g. latency). +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H +#define LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H + +#include "Assembler.h" +#include "BenchmarkCode.h" +#include "LlvmState.h" +#include "MCInstrDescView.h" +#include "RegisterAliasing.h" +#include "llvm/MC/MCInst.h" +#include "llvm/Support/Error.h" +#include <cstdlib> +#include <memory> +#include <vector> + +namespace exegesis { + +// A class representing failures that happened during Benchmark, they are used +// to report informations to the user. +class SnippetGeneratorFailure : public llvm::StringError { +public: + SnippetGeneratorFailure(const llvm::Twine &S); +}; + +// Common code for all benchmark modes. +class SnippetGenerator { +public: + explicit SnippetGenerator(const LLVMState &State); + + virtual ~SnippetGenerator(); + + // Calls generateCodeTemplate and expands it into one or more BenchmarkCode. + llvm::Expected<std::vector<BenchmarkCode>> + generateConfigurations(unsigned Opcode) const; + + // Given a snippet, computes which registers the setup code needs to define. + std::vector<unsigned> + computeRegsToDef(const std::vector<InstructionBuilder> &Snippet) const; + +protected: + const LLVMState &State; + const RegisterAliasingTrackerCache RATC; + + // Generates a single code template that has a self-dependency. + llvm::Expected<CodeTemplate> + generateSelfAliasingCodeTemplate(const Instruction &Instr) const; + // Generates a single code template without assignment constraints. + llvm::Expected<CodeTemplate> + generateUnconstrainedCodeTemplate(const Instruction &Instr, + llvm::StringRef Msg) const; + +private: + // API to be implemented by subclasses. + virtual llvm::Expected<CodeTemplate> + generateCodeTemplate(unsigned Opcode) const = 0; +}; + +} // namespace exegesis + +#endif // LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H |

