• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- 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 
20 #include "BenchmarkResult.h"
21 #include "BenchmarkRunner.h"
22 #include "LlvmState.h"
23 #include "llvm/ADT/Triple.h"
24 #include "llvm/CodeGen/TargetPassConfig.h"
25 #include "llvm/IR/LegacyPassManager.h"
26 #include "llvm/MC/MCInst.h"
27 #include "llvm/MC/MCRegisterInfo.h"
28 
29 namespace exegesis {
30 
31 class ExegesisTarget {
32 public:
33   // Targets can use this to add target-specific passes in assembleToStream();
addTargetSpecificPasses(llvm::PassManagerBase & PM)34   virtual void addTargetSpecificPasses(llvm::PassManagerBase &PM) const {}
35 
36   // Generates code to move a constant into a the given register.
37   virtual std::vector<llvm::MCInst>
setRegToConstant(const llvm::MCSubtargetInfo & STI,unsigned Reg)38   setRegToConstant(const llvm::MCSubtargetInfo &STI, unsigned Reg) const {
39     return {};
40   }
41 
42   // Creates a benchmark runner for the given mode.
43   std::unique_ptr<BenchmarkRunner>
44   createBenchmarkRunner(InstructionBenchmark::ModeE Mode,
45                         const LLVMState &State) const;
46 
47   // Returns the ExegesisTarget for the given triple or nullptr if the target
48   // does not exist.
49   static const ExegesisTarget *lookup(llvm::Triple TT);
50   // Returns the default (unspecialized) ExegesisTarget.
51   static const ExegesisTarget &getDefault();
52   // Registers a target. Not thread safe.
53   static void registerTarget(ExegesisTarget *T);
54 
55   virtual ~ExegesisTarget();
56 
57 private:
58   virtual bool matchesArch(llvm::Triple::ArchType Arch) const = 0;
59 
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 
67   const ExegesisTarget *Next = nullptr;
68 };
69 
70 } // namespace exegesis
71 
72 #endif // LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H
73