blob: 326d36b002f16f428e4cc1facf924cd13b405927 [file] [log] [blame]
Clement Courbetd939f6d2018-09-13 07:40:53 +00001//===-- 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 Chatelet7f8d3102018-09-26 11:57:24 +000021#include "CodeTemplate.h"
Clement Courbetd939f6d2018-09-13 07:40:53 +000022#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
31namespace exegesis {
32
33// A class representing failures that happened during Benchmark, they are used
34// to report informations to the user.
35class SnippetGeneratorFailure : public llvm::StringError {
36public:
37 SnippetGeneratorFailure(const llvm::Twine &S);
38};
39
40// Common code for all benchmark modes.
41class SnippetGenerator {
42public:
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 Chateletc96a97b2018-09-20 12:22:18 +000052 std::vector<RegisterValue> computeRegisterInitialValues(
53 const std::vector<InstructionBuilder> &Snippet) const;
Clement Courbetd939f6d2018-09-13 07:40:53 +000054
55protected:
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
67private:
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