Clement Courbet | 44b4c54 | 2018-06-19 11:28:59 +0000 | [diff] [blame] | 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 | |
Clement Courbet | 4860b98 | 2018-06-26 08:49:30 +0000 | [diff] [blame] | 20 | #include "BenchmarkResult.h" |
| 21 | #include "BenchmarkRunner.h" |
| 22 | #include "LlvmState.h" |
Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 23 | #include "SnippetGenerator.h" |
Clement Courbet | 44b4c54 | 2018-06-19 11:28:59 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/Triple.h" |
Clement Courbet | 6fd00e3 | 2018-06-20 11:54:35 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/TargetPassConfig.h" |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 26 | #include "llvm/IR/CallingConv.h" |
Clement Courbet | 6fd00e3 | 2018-06-20 11:54:35 +0000 | [diff] [blame] | 27 | #include "llvm/IR/LegacyPassManager.h" |
Clement Courbet | a51efc2 | 2018-06-25 13:12:02 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCInst.h" |
| 29 | #include "llvm/MC/MCRegisterInfo.h" |
Clement Courbet | 44b4c54 | 2018-06-19 11:28:59 +0000 | [diff] [blame] | 30 | |
| 31 | namespace exegesis { |
| 32 | |
| 33 | class ExegesisTarget { |
| 34 | public: |
Clement Courbet | 6fd00e3 | 2018-06-20 11:54:35 +0000 | [diff] [blame] | 35 | // Targets can use this to add target-specific passes in assembleToStream(); |
| 36 | virtual void addTargetSpecificPasses(llvm::PassManagerBase &PM) const {} |
| 37 | |
Clement Courbet | a51efc2 | 2018-06-25 13:12:02 +0000 | [diff] [blame] | 38 | // Generates code to move a constant into a the given register. |
Clement Courbet | e785169 | 2018-07-03 06:17:05 +0000 | [diff] [blame] | 39 | virtual std::vector<llvm::MCInst> |
Guillaume Chatelet | 5ad2909 | 2018-09-18 11:26:27 +0000 | [diff] [blame^] | 40 | setRegToConstant(const llvm::MCSubtargetInfo &STI, unsigned Reg) const = 0; |
Clement Courbet | a51efc2 | 2018-06-25 13:12:02 +0000 | [diff] [blame] | 41 | |
Guillaume Chatelet | 5ad2909 | 2018-09-18 11:26:27 +0000 | [diff] [blame^] | 42 | // Generates code to move a constant into a the given register. |
| 43 | virtual std::vector<llvm::MCInst> setRegTo(const llvm::MCSubtargetInfo &STI, |
| 44 | const llvm::APInt &Value, |
| 45 | unsigned Reg) const = 0; |
| 46 | |
| 47 | // Returns the register pointing to scratch memory, or 0 if this target |
| 48 | // does not support memory operands. The benchmark function uses the |
| 49 | // default calling convention. |
| 50 | virtual unsigned getScratchMemoryRegister(const llvm::Triple &) const = 0; |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 51 | |
| 52 | // Fills memory operands with references to the address at [Reg] + Offset. |
Guillaume Chatelet | 171f3f4 | 2018-08-02 11:12:02 +0000 | [diff] [blame] | 53 | virtual void fillMemoryOperands(InstructionBuilder &IB, unsigned Reg, |
Guillaume Chatelet | 5ad2909 | 2018-09-18 11:26:27 +0000 | [diff] [blame^] | 54 | unsigned Offset) const = 0; |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 55 | |
| 56 | // Returns the maximum number of bytes a load/store instruction can access at |
| 57 | // once. This is typically the size of the largest register available on the |
| 58 | // processor. Note that this only used as a hint to generate independant |
| 59 | // load/stores to/from memory, so the exact returned value does not really |
| 60 | // matter as long as it's large enough. |
Guillaume Chatelet | 5ad2909 | 2018-09-18 11:26:27 +0000 | [diff] [blame^] | 61 | virtual unsigned getMaxMemoryAccessSize() const = 0; |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 62 | |
Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 63 | // Creates a snippet generator for the given mode. |
| 64 | std::unique_ptr<SnippetGenerator> |
| 65 | createSnippetGenerator(InstructionBenchmark::ModeE Mode, |
| 66 | const LLVMState &State) const; |
Clement Courbet | 4860b98 | 2018-06-26 08:49:30 +0000 | [diff] [blame] | 67 | // Creates a benchmark runner for the given mode. |
| 68 | std::unique_ptr<BenchmarkRunner> |
| 69 | createBenchmarkRunner(InstructionBenchmark::ModeE Mode, |
| 70 | const LLVMState &State) const; |
| 71 | |
Clement Courbet | 44b4c54 | 2018-06-19 11:28:59 +0000 | [diff] [blame] | 72 | // Returns the ExegesisTarget for the given triple or nullptr if the target |
| 73 | // does not exist. |
Clement Courbet | 6fd00e3 | 2018-06-20 11:54:35 +0000 | [diff] [blame] | 74 | static const ExegesisTarget *lookup(llvm::Triple TT); |
Clement Courbet | 4860b98 | 2018-06-26 08:49:30 +0000 | [diff] [blame] | 75 | // Returns the default (unspecialized) ExegesisTarget. |
| 76 | static const ExegesisTarget &getDefault(); |
Clement Courbet | 44b4c54 | 2018-06-19 11:28:59 +0000 | [diff] [blame] | 77 | // Registers a target. Not thread safe. |
| 78 | static void registerTarget(ExegesisTarget *T); |
| 79 | |
Roman Lebedev | 3de9664 | 2018-06-19 11:58:10 +0000 | [diff] [blame] | 80 | virtual ~ExegesisTarget(); |
Clement Courbet | 44b4c54 | 2018-06-19 11:28:59 +0000 | [diff] [blame] | 81 | |
| 82 | private: |
| 83 | virtual bool matchesArch(llvm::Triple::ArchType Arch) const = 0; |
Clement Courbet | 4860b98 | 2018-06-26 08:49:30 +0000 | [diff] [blame] | 84 | |
Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 85 | // Targets can implement their own snippet generators/benchmarks runners by |
Clement Courbet | 4860b98 | 2018-06-26 08:49:30 +0000 | [diff] [blame] | 86 | // implementing these. |
Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 87 | std::unique_ptr<SnippetGenerator> virtual createLatencySnippetGenerator( |
| 88 | const LLVMState &State) const; |
| 89 | std::unique_ptr<SnippetGenerator> virtual createUopsSnippetGenerator( |
| 90 | const LLVMState &State) const; |
Clement Courbet | 4860b98 | 2018-06-26 08:49:30 +0000 | [diff] [blame] | 91 | std::unique_ptr<BenchmarkRunner> virtual createLatencyBenchmarkRunner( |
| 92 | const LLVMState &State) const; |
| 93 | std::unique_ptr<BenchmarkRunner> virtual createUopsBenchmarkRunner( |
| 94 | const LLVMState &State) const; |
| 95 | |
Clement Courbet | cff2caa | 2018-06-25 11:22:23 +0000 | [diff] [blame] | 96 | const ExegesisTarget *Next = nullptr; |
Clement Courbet | 44b4c54 | 2018-06-19 11:28:59 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
Clement Courbet | cff2caa | 2018-06-25 11:22:23 +0000 | [diff] [blame] | 99 | } // namespace exegesis |
Clement Courbet | 44b4c54 | 2018-06-19 11:28:59 +0000 | [diff] [blame] | 100 | |
| 101 | #endif // LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H |