blob: 41d77e3170eda6e000cb7c9a0e5529dd08df1cb2 [file] [log] [blame]
Clement Courbet44b4c542018-06-19 11:28:59 +00001//===-- Target.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///
12/// Classes that handle the creation of target-specific objects. This is
13/// similar to llvm::Target/TargetRegistry.
14///
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H
18#define LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H
19
Clement Courbet4860b982018-06-26 08:49:30 +000020#include "BenchmarkResult.h"
21#include "BenchmarkRunner.h"
22#include "LlvmState.h"
Clement Courbetd939f6d2018-09-13 07:40:53 +000023#include "SnippetGenerator.h"
Clement Courbet44b4c542018-06-19 11:28:59 +000024#include "llvm/ADT/Triple.h"
Clement Courbet6fd00e32018-06-20 11:54:35 +000025#include "llvm/CodeGen/TargetPassConfig.h"
Guillaume Chateletfb943542018-08-01 14:41:45 +000026#include "llvm/IR/CallingConv.h"
Clement Courbet6fd00e32018-06-20 11:54:35 +000027#include "llvm/IR/LegacyPassManager.h"
Clement Courbeta51efc22018-06-25 13:12:02 +000028#include "llvm/MC/MCInst.h"
29#include "llvm/MC/MCRegisterInfo.h"
Clement Courbet44b4c542018-06-19 11:28:59 +000030
31namespace exegesis {
32
33class ExegesisTarget {
34public:
Clement Courbet6fd00e32018-06-20 11:54:35 +000035 // Targets can use this to add target-specific passes in assembleToStream();
36 virtual void addTargetSpecificPasses(llvm::PassManagerBase &PM) const {}
37
Clement Courbeta51efc22018-06-25 13:12:02 +000038 // Generates code to move a constant into a the given register.
Simon Pilgrim02426892018-09-18 15:35:49 +000039 virtual std::vector<llvm::MCInst> setRegTo(const llvm::MCSubtargetInfo &STI,
40 const llvm::APInt &Value,
41 unsigned Reg) const = 0;
Guillaume Chatelet5ad29092018-09-18 11:26:27 +000042
43 // Returns the register pointing to scratch memory, or 0 if this target
44 // does not support memory operands. The benchmark function uses the
45 // default calling convention.
Simon Pilgrim02426892018-09-18 15:35:49 +000046 virtual unsigned getScratchMemoryRegister(const llvm::Triple &) const = 0;
Guillaume Chateletfb943542018-08-01 14:41:45 +000047
48 // Fills memory operands with references to the address at [Reg] + Offset.
Guillaume Chatelet171f3f42018-08-02 11:12:02 +000049 virtual void fillMemoryOperands(InstructionBuilder &IB, unsigned Reg,
Simon Pilgrim02426892018-09-18 15:35:49 +000050 unsigned Offset) const = 0;
Guillaume Chateletfb943542018-08-01 14:41:45 +000051
52 // Returns the maximum number of bytes a load/store instruction can access at
53 // once. This is typically the size of the largest register available on the
54 // processor. Note that this only used as a hint to generate independant
55 // load/stores to/from memory, so the exact returned value does not really
56 // matter as long as it's large enough.
Simon Pilgrim02426892018-09-18 15:35:49 +000057 virtual unsigned getMaxMemoryAccessSize() const = 0;
Guillaume Chateletfb943542018-08-01 14:41:45 +000058
Clement Courbetd939f6d2018-09-13 07:40:53 +000059 // Creates a snippet generator for the given mode.
60 std::unique_ptr<SnippetGenerator>
61 createSnippetGenerator(InstructionBenchmark::ModeE Mode,
62 const LLVMState &State) const;
Clement Courbet4860b982018-06-26 08:49:30 +000063 // Creates a benchmark runner for the given mode.
64 std::unique_ptr<BenchmarkRunner>
65 createBenchmarkRunner(InstructionBenchmark::ModeE Mode,
66 const LLVMState &State) const;
67
Clement Courbet44b4c542018-06-19 11:28:59 +000068 // Returns the ExegesisTarget for the given triple or nullptr if the target
69 // does not exist.
Clement Courbet6fd00e32018-06-20 11:54:35 +000070 static const ExegesisTarget *lookup(llvm::Triple TT);
Clement Courbet4860b982018-06-26 08:49:30 +000071 // Returns the default (unspecialized) ExegesisTarget.
72 static const ExegesisTarget &getDefault();
Clement Courbet44b4c542018-06-19 11:28:59 +000073 // Registers a target. Not thread safe.
74 static void registerTarget(ExegesisTarget *T);
75
Roman Lebedev3de96642018-06-19 11:58:10 +000076 virtual ~ExegesisTarget();
Clement Courbet44b4c542018-06-19 11:28:59 +000077
78private:
79 virtual bool matchesArch(llvm::Triple::ArchType Arch) const = 0;
Clement Courbet4860b982018-06-26 08:49:30 +000080
Clement Courbetd939f6d2018-09-13 07:40:53 +000081 // Targets can implement their own snippet generators/benchmarks runners by
Clement Courbet4860b982018-06-26 08:49:30 +000082 // implementing these.
Clement Courbetd939f6d2018-09-13 07:40:53 +000083 std::unique_ptr<SnippetGenerator> virtual createLatencySnippetGenerator(
84 const LLVMState &State) const;
85 std::unique_ptr<SnippetGenerator> virtual createUopsSnippetGenerator(
86 const LLVMState &State) const;
Clement Courbet4860b982018-06-26 08:49:30 +000087 std::unique_ptr<BenchmarkRunner> virtual createLatencyBenchmarkRunner(
88 const LLVMState &State) const;
89 std::unique_ptr<BenchmarkRunner> virtual createUopsBenchmarkRunner(
90 const LLVMState &State) const;
91
Clement Courbetcff2caa2018-06-25 11:22:23 +000092 const ExegesisTarget *Next = nullptr;
Clement Courbet44b4c542018-06-19 11:28:59 +000093};
94
Clement Courbetcff2caa2018-06-25 11:22:23 +000095} // namespace exegesis
Clement Courbet44b4c542018-06-19 11:28:59 +000096
97#endif // LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H