blob: 9f8fbc3cd915c4c7e8eaab33d52c4878729464e9 [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 Courbet44b4c542018-06-19 11:28:59 +000023#include "llvm/ADT/Triple.h"
Clement Courbet6fd00e32018-06-20 11:54:35 +000024#include "llvm/CodeGen/TargetPassConfig.h"
Guillaume Chateletfb943542018-08-01 14:41:45 +000025#include "llvm/IR/CallingConv.h"
Clement Courbet6fd00e32018-06-20 11:54:35 +000026#include "llvm/IR/LegacyPassManager.h"
Clement Courbeta51efc22018-06-25 13:12:02 +000027#include "llvm/MC/MCInst.h"
28#include "llvm/MC/MCRegisterInfo.h"
Clement Courbet44b4c542018-06-19 11:28:59 +000029
30namespace exegesis {
31
32class ExegesisTarget {
33public:
Clement Courbet6fd00e32018-06-20 11:54:35 +000034 // Targets can use this to add target-specific passes in assembleToStream();
35 virtual void addTargetSpecificPasses(llvm::PassManagerBase &PM) const {}
36
Clement Courbeta51efc22018-06-25 13:12:02 +000037 // Generates code to move a constant into a the given register.
Clement Courbete7851692018-07-03 06:17:05 +000038 virtual std::vector<llvm::MCInst>
39 setRegToConstant(const llvm::MCSubtargetInfo &STI, unsigned Reg) const {
Clement Courbeta51efc22018-06-25 13:12:02 +000040 return {};
41 }
42
Guillaume Chateletfb943542018-08-01 14:41:45 +000043 // Returns the register pointing to scratch memory, or 0 if this target does
44 // not support memory operands. The benchmark function uses the default
45 // calling convention.
46 virtual unsigned getScratchMemoryRegister(const llvm::Triple &) const {
47 return 0;
48 }
49
50 // Fills memory operands with references to the address at [Reg] + Offset.
Guillaume Chatelet171f3f42018-08-02 11:12:02 +000051 virtual void fillMemoryOperands(InstructionBuilder &IB, unsigned Reg,
Guillaume Chateletfb943542018-08-01 14:41:45 +000052 unsigned Offset) const {
53 llvm_unreachable(
54 "fillMemoryOperands() requires getScratchMemoryRegister() > 0");
55 }
56
57 // Returns the maximum number of bytes a load/store instruction can access at
58 // once. This is typically the size of the largest register available on the
59 // processor. Note that this only used as a hint to generate independant
60 // load/stores to/from memory, so the exact returned value does not really
61 // matter as long as it's large enough.
62 virtual unsigned getMaxMemoryAccessSize() const { return 0; }
63
Clement Courbet4860b982018-06-26 08:49:30 +000064 // Creates a benchmark runner for the given mode.
65 std::unique_ptr<BenchmarkRunner>
66 createBenchmarkRunner(InstructionBenchmark::ModeE Mode,
67 const LLVMState &State) const;
68
Clement Courbet44b4c542018-06-19 11:28:59 +000069 // Returns the ExegesisTarget for the given triple or nullptr if the target
70 // does not exist.
Clement Courbet6fd00e32018-06-20 11:54:35 +000071 static const ExegesisTarget *lookup(llvm::Triple TT);
Clement Courbet4860b982018-06-26 08:49:30 +000072 // Returns the default (unspecialized) ExegesisTarget.
73 static const ExegesisTarget &getDefault();
Clement Courbet44b4c542018-06-19 11:28:59 +000074 // Registers a target. Not thread safe.
75 static void registerTarget(ExegesisTarget *T);
76
Roman Lebedev3de96642018-06-19 11:58:10 +000077 virtual ~ExegesisTarget();
Clement Courbet44b4c542018-06-19 11:28:59 +000078
79private:
80 virtual bool matchesArch(llvm::Triple::ArchType Arch) const = 0;
Clement Courbet4860b982018-06-26 08:49:30 +000081
82 // Targets can implement their own Latency/Uops benchmarks runners by
83 // implementing these.
84 std::unique_ptr<BenchmarkRunner> virtual createLatencyBenchmarkRunner(
85 const LLVMState &State) const;
86 std::unique_ptr<BenchmarkRunner> virtual createUopsBenchmarkRunner(
87 const LLVMState &State) const;
88
Clement Courbetcff2caa2018-06-25 11:22:23 +000089 const ExegesisTarget *Next = nullptr;
Clement Courbet44b4c542018-06-19 11:28:59 +000090};
91
Clement Courbetcff2caa2018-06-25 11:22:23 +000092} // namespace exegesis
Clement Courbet44b4c542018-06-19 11:28:59 +000093
94#endif // LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H