1 //===-- Target.cpp ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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()))
29 void ExegesisTarget::registerTarget(ExegesisTarget
*Target
) {
30 if (FirstTarget
== nullptr) {
34 if (Target
->Next
!= nullptr)
35 return; // Already registered.
36 Target
->Next
= FirstTarget
;
40 std::unique_ptr
<SnippetGenerator
>
41 ExegesisTarget::createSnippetGenerator(InstructionBenchmark::ModeE Mode
,
42 const LLVMState
&State
) const {
44 case InstructionBenchmark::Unknown
:
46 case InstructionBenchmark::Latency
:
47 return createLatencySnippetGenerator(State
);
48 case InstructionBenchmark::Uops
:
49 return createUopsSnippetGenerator(State
);
54 std::unique_ptr
<BenchmarkRunner
>
55 ExegesisTarget::createBenchmarkRunner(InstructionBenchmark::ModeE Mode
,
56 const LLVMState
&State
) const {
58 case InstructionBenchmark::Unknown
:
60 case InstructionBenchmark::Latency
:
61 return createLatencyBenchmarkRunner(State
);
62 case InstructionBenchmark::Uops
:
63 return createUopsBenchmarkRunner(State
);
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
);
90 // Default implementation.
91 class ExegesisDefaultTarget
: public ExegesisTarget
{
93 std::vector
<llvm::MCInst
> setRegTo(const llvm::MCSubtargetInfo
&STI
,
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");
107 const ExegesisTarget
&ExegesisTarget::getDefault() {
108 static ExegesisDefaultTarget Target
;
112 } // namespace exegesis