[llvm-exegesis] Implements a cache of Instruction objects.
[llvm-core.git] / tools / llvm-exegesis / lib / Target.cpp
blobb7828a13da0483b14fd56bf3b0eecb8ee554f133
1 //===-- Target.cpp ----------------------------------------------*- 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 #include "Target.h"
11 #include "Latency.h"
12 #include "Uops.h"
14 namespace llvm {
15 namespace exegesis {
17 ExegesisTarget::~ExegesisTarget() {} // anchor.
19 static ExegesisTarget *FirstTarget = nullptr;
21 const ExegesisTarget *ExegesisTarget::lookup(llvm::Triple TT) {
22 for (const ExegesisTarget *T = FirstTarget; T != nullptr; T = T->Next) {
23 if (T->matchesArch(TT.getArch()))
24 return T;
26 return nullptr;
29 void ExegesisTarget::registerTarget(ExegesisTarget *Target) {
30 if (FirstTarget == nullptr) {
31 FirstTarget = Target;
32 return;
34 if (Target->Next != nullptr)
35 return; // Already registered.
36 Target->Next = FirstTarget;
37 FirstTarget = Target;
40 std::unique_ptr<SnippetGenerator>
41 ExegesisTarget::createSnippetGenerator(InstructionBenchmark::ModeE Mode,
42 const LLVMState &State) const {
43 switch (Mode) {
44 case InstructionBenchmark::Unknown:
45 return nullptr;
46 case InstructionBenchmark::Latency:
47 return createLatencySnippetGenerator(State);
48 case InstructionBenchmark::Uops:
49 return createUopsSnippetGenerator(State);
51 return nullptr;
54 std::unique_ptr<BenchmarkRunner>
55 ExegesisTarget::createBenchmarkRunner(InstructionBenchmark::ModeE Mode,
56 const LLVMState &State) const {
57 switch (Mode) {
58 case InstructionBenchmark::Unknown:
59 return nullptr;
60 case InstructionBenchmark::Latency:
61 return createLatencyBenchmarkRunner(State);
62 case InstructionBenchmark::Uops:
63 return createUopsBenchmarkRunner(State);
65 return nullptr;
68 std::unique_ptr<SnippetGenerator>
69 ExegesisTarget::createLatencySnippetGenerator(const LLVMState &State) const {
70 return llvm::make_unique<LatencySnippetGenerator>(State);
73 std::unique_ptr<SnippetGenerator>
74 ExegesisTarget::createUopsSnippetGenerator(const LLVMState &State) const {
75 return llvm::make_unique<UopsSnippetGenerator>(State);
78 std::unique_ptr<BenchmarkRunner>
79 ExegesisTarget::createLatencyBenchmarkRunner(const LLVMState &State) const {
80 return llvm::make_unique<LatencyBenchmarkRunner>(State);
83 std::unique_ptr<BenchmarkRunner>
84 ExegesisTarget::createUopsBenchmarkRunner(const LLVMState &State) const {
85 return llvm::make_unique<UopsBenchmarkRunner>(State);
88 namespace {
90 // Default implementation.
91 class ExegesisDefaultTarget : public ExegesisTarget {
92 private:
93 std::vector<llvm::MCInst> setRegTo(const llvm::MCSubtargetInfo &STI,
94 unsigned Reg,
95 const llvm::APInt &Value) const override {
96 llvm_unreachable("Not yet implemented");
99 bool matchesArch(llvm::Triple::ArchType Arch) const override {
100 llvm_unreachable("never called");
101 return false;
105 } // namespace
107 const ExegesisTarget &ExegesisTarget::getDefault() {
108 static ExegesisDefaultTarget Target;
109 return Target;
112 } // namespace exegesis
113 } // namespace llvm