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" 10 11 #include "Latency.h" 12 #include "Uops.h" 13 14 namespace exegesis { 15 ~ExegesisTarget()16ExegesisTarget::~ExegesisTarget() {} // anchor. 17 18 static ExegesisTarget *FirstTarget = nullptr; 19 lookup(llvm::Triple TT)20const ExegesisTarget *ExegesisTarget::lookup(llvm::Triple TT) { 21 for (const ExegesisTarget *T = FirstTarget; T != nullptr; T = T->Next) { 22 if (T->matchesArch(TT.getArch())) 23 return T; 24 } 25 return nullptr; 26 } 27 registerTarget(ExegesisTarget * Target)28void ExegesisTarget::registerTarget(ExegesisTarget *Target) { 29 if (FirstTarget == nullptr) { 30 FirstTarget = Target; 31 return; 32 } 33 assert(Target->Next == nullptr && "target has already been registered"); 34 if (Target->Next != nullptr) 35 return; 36 Target->Next = FirstTarget; 37 FirstTarget = Target; 38 } 39 40 std::unique_ptr<BenchmarkRunner> createBenchmarkRunner(InstructionBenchmark::ModeE Mode,const LLVMState & State) const41ExegesisTarget::createBenchmarkRunner(InstructionBenchmark::ModeE Mode, 42 const LLVMState &State) const { 43 switch (Mode) { 44 case InstructionBenchmark::Unknown: 45 return nullptr; 46 case InstructionBenchmark::Latency: 47 return createLatencyBenchmarkRunner(State); 48 case InstructionBenchmark::Uops: 49 return createUopsBenchmarkRunner(State); 50 } 51 return nullptr; 52 } 53 54 std::unique_ptr<BenchmarkRunner> createLatencyBenchmarkRunner(const LLVMState & State) const55ExegesisTarget::createLatencyBenchmarkRunner(const LLVMState &State) const { 56 return llvm::make_unique<LatencyBenchmarkRunner>(State); 57 } 58 59 std::unique_ptr<BenchmarkRunner> createUopsBenchmarkRunner(const LLVMState & State) const60ExegesisTarget::createUopsBenchmarkRunner(const LLVMState &State) const { 61 return llvm::make_unique<UopsBenchmarkRunner>(State); 62 } 63 64 namespace { 65 66 // Default implementation. 67 class ExegesisDefaultTarget : public ExegesisTarget { 68 private: matchesArch(llvm::Triple::ArchType Arch) const69 bool matchesArch(llvm::Triple::ArchType Arch) const override { 70 llvm_unreachable("never called"); 71 return false; 72 } 73 }; 74 75 } // namespace 76 getDefault()77const ExegesisTarget &ExegesisTarget::getDefault() { 78 static ExegesisDefaultTarget Target; 79 return Target; 80 } 81 82 } // namespace exegesis 83