blob: cb87e3a6d4bf6ef88ddf168be213b7960a635f3c [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.
37 virtual std::vector<llvm::MCInst> setRegToConstant(unsigned Reg) const {
38 return {};
39 }
40
Clement Courbet4860b982018-06-26 08:49:30 +000041 // Creates a benchmark runner for the given mode.
42 std::unique_ptr<BenchmarkRunner>
43 createBenchmarkRunner(InstructionBenchmark::ModeE Mode,
44 const LLVMState &State) const;
45
Clement Courbet44b4c542018-06-19 11:28:59 +000046 // Returns the ExegesisTarget for the given triple or nullptr if the target
47 // does not exist.
Clement Courbet6fd00e32018-06-20 11:54:35 +000048 static const ExegesisTarget *lookup(llvm::Triple TT);
Clement Courbet4860b982018-06-26 08:49:30 +000049 // Returns the default (unspecialized) ExegesisTarget.
50 static const ExegesisTarget &getDefault();
Clement Courbet44b4c542018-06-19 11:28:59 +000051 // Registers a target. Not thread safe.
52 static void registerTarget(ExegesisTarget *T);
53
Roman Lebedev3de96642018-06-19 11:58:10 +000054 virtual ~ExegesisTarget();
Clement Courbet44b4c542018-06-19 11:28:59 +000055
56private:
57 virtual bool matchesArch(llvm::Triple::ArchType Arch) const = 0;
Clement Courbet4860b982018-06-26 08:49:30 +000058
59 // Targets can implement their own Latency/Uops benchmarks runners by
60 // implementing these.
61 std::unique_ptr<BenchmarkRunner> virtual createLatencyBenchmarkRunner(
62 const LLVMState &State) const;
63 std::unique_ptr<BenchmarkRunner> virtual createUopsBenchmarkRunner(
64 const LLVMState &State) const;
65
Clement Courbetcff2caa2018-06-25 11:22:23 +000066 const ExegesisTarget *Next = nullptr;
Clement Courbet44b4c542018-06-19 11:28:59 +000067};
68
Clement Courbetcff2caa2018-06-25 11:22:23 +000069} // namespace exegesis
Clement Courbet44b4c542018-06-19 11:28:59 +000070
71#endif // LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H