blob: ced8ebc5a287eb39e7434cd542024a15c53d07a2 [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"
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>
29
30namespace exegesis {
31
32// A class representing failures that happened during Benchmark, they are used
33// to report informations to the user.
34class SnippetGeneratorFailure : public llvm::StringError {
35public:
36 SnippetGeneratorFailure(const llvm::Twine &S);
37};
38
39// Common code for all benchmark modes.
40class SnippetGenerator {
41public:
42 explicit SnippetGenerator(const LLVMState &State);
43
44 virtual ~SnippetGenerator();
45
46 // Calls generateCodeTemplate and expands it into one or more BenchmarkCode.
47 llvm::Expected<std::vector<BenchmarkCode>>
48 generateConfigurations(unsigned Opcode) const;
49
50 // Given a snippet, computes which registers the setup code needs to define.
51 std::vector<unsigned>
52 computeRegsToDef(const std::vector<InstructionBuilder> &Snippet) const;
53
54protected:
55 const LLVMState &State;
56 const RegisterAliasingTrackerCache RATC;
57
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;
65
66private:
67 // API to be implemented by subclasses.
68 virtual llvm::Expected<CodeTemplate>
69 generateCodeTemplate(unsigned Opcode) const = 0;
70};
71
72} // namespace exegesis
73
74#endif // LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H