| Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 1 | //===-- Uops.h --------------------------------------------------*- C++ -*-===// |
| 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
| 10 | /// A BenchmarkRunner implementation to measure uop decomposition. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_TOOLS_LLVM_EXEGESIS_UOPS_H |
| 15 | #define LLVM_TOOLS_LLVM_EXEGESIS_UOPS_H |
| 16 | |
| 17 | #include "BenchmarkRunner.h" |
| Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 18 | #include "SnippetGenerator.h" |
| Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 19 | |
| Fangrui Song | 32401af | 2018-10-22 17:10:47 +0000 | [diff] [blame] | 20 | namespace llvm { |
| Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 21 | namespace exegesis { |
| 22 | |
| Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 23 | class UopsSnippetGenerator : public SnippetGenerator { |
| Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 24 | public: |
| Clement Courbet | 2cd0f28 | 2019-10-08 14:30:24 +0000 | [diff] [blame^] | 25 | using SnippetGenerator::SnippetGenerator; |
| Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 26 | ~UopsSnippetGenerator() override; |
| Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 27 | |
| Guillaume Chatelet | 296a862 | 2018-10-15 09:09:19 +0000 | [diff] [blame] | 28 | llvm::Expected<std::vector<CodeTemplate>> |
| Clement Courbet | 8ef97e1 | 2019-09-27 08:04:10 +0000 | [diff] [blame] | 29 | generateCodeTemplates(const Instruction &Instr, |
| 30 | const BitVector &ForbiddenRegisters) const override; |
| Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 31 | |
| Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 32 | static constexpr const size_t kMinNumDifferentAddresses = 6; |
| 33 | |
| Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 34 | private: |
| Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 35 | // Instantiates memory operands within a snippet. |
| 36 | // To make computations as parallel as possible, we generate independant |
| 37 | // memory locations for instructions that load and store. If there are less |
| 38 | // than kMinNumDifferentAddresses in the original snippet, we duplicate |
| 39 | // instructions until there are this number of instructions. |
| 40 | // For example, assuming kMinNumDifferentAddresses=5 and |
| 41 | // getMaxMemoryAccessSize()=64, if the original snippet is: |
| 42 | // mov eax, [memory] |
| 43 | // we might generate: |
| 44 | // mov eax, [rdi] |
| 45 | // mov eax, [rdi + 64] |
| 46 | // mov eax, [rdi + 128] |
| 47 | // mov eax, [rdi + 192] |
| 48 | // mov eax, [rdi + 256] |
| 49 | // If the original snippet is: |
| 50 | // mov eax, [memory] |
| 51 | // add eax, [memory] |
| 52 | // we might generate: |
| 53 | // mov eax, [rdi] |
| 54 | // add eax, [rdi + 64] |
| 55 | // mov eax, [rdi + 128] |
| 56 | // add eax, [rdi + 192] |
| 57 | // mov eax, [rdi + 256] |
| Guillaume Chatelet | 70ac019 | 2018-09-27 09:23:04 +0000 | [diff] [blame] | 58 | void instantiateMemoryOperands( |
| 59 | unsigned ScratchSpaceReg, |
| 60 | std::vector<InstructionTemplate> &SnippetTemplate) const; |
| Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 63 | class UopsBenchmarkRunner : public BenchmarkRunner { |
| 64 | public: |
| 65 | UopsBenchmarkRunner(const LLVMState &State) |
| 66 | : BenchmarkRunner(State, InstructionBenchmark::Uops) {} |
| 67 | ~UopsBenchmarkRunner() override; |
| 68 | |
| 69 | static constexpr const size_t kMinNumDifferentAddresses = 6; |
| 70 | |
| 71 | private: |
| Clement Courbet | f973c2d | 2018-10-17 15:04:15 +0000 | [diff] [blame] | 72 | llvm::Expected<std::vector<BenchmarkMeasure>> |
| 73 | runMeasurements(const FunctionExecutor &Executor) const override; |
| Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
| Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 76 | } // namespace exegesis |
| Fangrui Song | 32401af | 2018-10-22 17:10:47 +0000 | [diff] [blame] | 77 | } // namespace llvm |
| Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 78 | |
| 79 | #endif // LLVM_TOOLS_LLVM_EXEGESIS_UOPS_H |