Miloš Stojanović | 24b7b99 | 2020-01-17 14:28:54 +0100 | [diff] [blame] | 1 | //===-- ParallelSnippetGenerator.h ------------------------------*- C++ -*-===// |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 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 |
Miloš Stojanović | 24b7b99 | 2020-01-17 14:28:54 +0100 | [diff] [blame] | 10 | /// A SnippetGenerator implementation to create parallel instruction snippets. |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Miloš Stojanović | 24b7b99 | 2020-01-17 14:28:54 +0100 | [diff] [blame] | 14 | #ifndef LLVM_TOOLS_LLVM_EXEGESIS_PARALLELSNIPPETGENERATOR_H |
| 15 | #define LLVM_TOOLS_LLVM_EXEGESIS_PARALLELSNIPPETGENERATOR_H |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 16 | |
Clement Courbet | d939f6d | 2018-09-13 07:40:53 +0000 | [diff] [blame] | 17 | #include "SnippetGenerator.h" |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 18 | |
Fangrui Song | 32401af | 2018-10-22 17:10:47 +0000 | [diff] [blame] | 19 | namespace llvm { |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 20 | namespace exegesis { |
| 21 | |
Miloš Stojanović | 24b7b99 | 2020-01-17 14:28:54 +0100 | [diff] [blame] | 22 | class ParallelSnippetGenerator : public SnippetGenerator { |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 23 | public: |
Clement Courbet | 2cd0f28 | 2019-10-08 14:30:24 +0000 | [diff] [blame] | 24 | using SnippetGenerator::SnippetGenerator; |
Miloš Stojanović | 24b7b99 | 2020-01-17 14:28:54 +0100 | [diff] [blame] | 25 | ~ParallelSnippetGenerator() override; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 26 | |
Clement Courbet | 50cdd56 | 2019-10-09 11:58:42 +0000 | [diff] [blame] | 27 | Expected<std::vector<CodeTemplate>> |
Roman Lebedev | 6030fe0 | 2020-02-12 20:54:39 +0300 | [diff] [blame] | 28 | generateCodeTemplates(InstructionTemplate Variant, |
Clement Courbet | 8ef97e1 | 2019-09-27 08:04:10 +0000 | [diff] [blame] | 29 | const BitVector &ForbiddenRegisters) const override; |
Guillaume Chatelet | c9f727b | 2018-06-13 13:24:41 +0000 | [diff] [blame] | 30 | |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 31 | static constexpr const size_t kMinNumDifferentAddresses = 6; |
| 32 | |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 33 | private: |
Guillaume Chatelet | fb94354 | 2018-08-01 14:41:45 +0000 | [diff] [blame] | 34 | // Instantiates memory operands within a snippet. |
| 35 | // To make computations as parallel as possible, we generate independant |
| 36 | // memory locations for instructions that load and store. If there are less |
| 37 | // than kMinNumDifferentAddresses in the original snippet, we duplicate |
| 38 | // instructions until there are this number of instructions. |
| 39 | // For example, assuming kMinNumDifferentAddresses=5 and |
| 40 | // getMaxMemoryAccessSize()=64, if the original snippet is: |
| 41 | // mov eax, [memory] |
| 42 | // we might generate: |
| 43 | // mov eax, [rdi] |
| 44 | // mov eax, [rdi + 64] |
| 45 | // mov eax, [rdi + 128] |
| 46 | // mov eax, [rdi + 192] |
| 47 | // mov eax, [rdi + 256] |
| 48 | // If the original snippet is: |
| 49 | // mov eax, [memory] |
| 50 | // add eax, [memory] |
| 51 | // we might generate: |
| 52 | // mov eax, [rdi] |
| 53 | // add eax, [rdi + 64] |
| 54 | // mov eax, [rdi + 128] |
| 55 | // add eax, [rdi + 192] |
| 56 | // mov eax, [rdi + 256] |
Guillaume Chatelet | 70ac019 | 2018-09-27 09:23:04 +0000 | [diff] [blame] | 57 | void instantiateMemoryOperands( |
| 58 | unsigned ScratchSpaceReg, |
| 59 | std::vector<InstructionTemplate> &SnippetTemplate) const; |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 62 | } // namespace exegesis |
Fangrui Song | 32401af | 2018-10-22 17:10:47 +0000 | [diff] [blame] | 63 | } // namespace llvm |
Clement Courbet | ac74acd | 2018-04-04 11:37:06 +0000 | [diff] [blame] | 64 | |
Miloš Stojanović | 24b7b99 | 2020-01-17 14:28:54 +0100 | [diff] [blame] | 65 | #endif // LLVM_TOOLS_LLVM_EXEGESIS_PARALLELSNIPPETGENERATOR_H |