1 //===-- SnippetGenerator.h --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Defines the abstract SnippetGenerator class for generating code that allows
12 /// measuring a certain property of instructions (e.g. latency).
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"
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
{
36 SnippetGeneratorFailure(const llvm::Twine
&S
);
39 // Common code for all benchmark modes.
40 class SnippetGenerator
{
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;
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;
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