blob: 4f1f2869b749e35ecd6080f24c0b1995143570e3 [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"
25#include "llvm/IR/LegacyPassManager.h"
Clement Courbeta51efc22018-06-25 13:12:02 +000026#include "llvm/MC/MCInst.h"
27#include "llvm/MC/MCRegisterInfo.h"
Clement Courbet44b4c542018-06-19 11:28:59 +000028
29namespace exegesis {
30
31class ExegesisTarget {
32public:
Clement Courbet6fd00e32018-06-20 11:54:35 +000033 // Targets can use this to add target-specific passes in assembleToStream();
34 virtual void addTargetSpecificPasses(llvm::PassManagerBase &PM) const {}
35
Clement Courbeta51efc22018-06-25 13:12:02 +000036 // Generates code to move a constant into a the given register.
Clement Courbete7851692018-07-03 06:17:05 +000037 virtual std::vector<llvm::MCInst>
38 setRegToConstant(const llvm::MCSubtargetInfo &STI, unsigned Reg) const {
Clement Courbeta51efc22018-06-25 13:12:02 +000039 return {};
40 }
41
Clement Courbet4860b982018-06-26 08:49:30 +000042 // Creates a benchmark runner for the given mode.
43 std::unique_ptr<BenchmarkRunner>
44 createBenchmarkRunner(InstructionBenchmark::ModeE Mode,
45 const LLVMState &State) const;
46
Clement Courbet44b4c542018-06-19 11:28:59 +000047 // Returns the ExegesisTarget for the given triple or nullptr if the target
48 // does not exist.
Clement Courbet6fd00e32018-06-20 11:54:35 +000049 static const ExegesisTarget *lookup(llvm::Triple TT);
Clement Courbet4860b982018-06-26 08:49:30 +000050 // Returns the default (unspecialized) ExegesisTarget.
51 static const ExegesisTarget &getDefault();
Clement Courbet44b4c542018-06-19 11:28:59 +000052 // Registers a target. Not thread safe.
53 static void registerTarget(ExegesisTarget *T);
54
Roman Lebedev3de96642018-06-19 11:58:10 +000055 virtual ~ExegesisTarget();
Clement Courbet44b4c542018-06-19 11:28:59 +000056
57private:
58 virtual bool matchesArch(llvm::Triple::ArchType Arch) const = 0;
Clement Courbet4860b982018-06-26 08:49:30 +000059
60 // Targets can implement their own Latency/Uops benchmarks runners by
61 // implementing these.
62 std::unique_ptr<BenchmarkRunner> virtual createLatencyBenchmarkRunner(
63 const LLVMState &State) const;
64 std::unique_ptr<BenchmarkRunner> virtual createUopsBenchmarkRunner(
65 const LLVMState &State) const;
66
Clement Courbetcff2caa2018-06-25 11:22:23 +000067 const ExegesisTarget *Next = nullptr;
Clement Courbet44b4c542018-06-19 11:28:59 +000068};
69
Clement Courbetcff2caa2018-06-25 11:22:23 +000070} // namespace exegesis
Clement Courbet44b4c542018-06-19 11:28:59 +000071
72#endif // LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H