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