blob: 94eb4e26eb5881acae1205a446b0949669728152 [file] [log] [blame]
Miloš Stojanović24b7b992020-01-17 14:28:54 +01001//===-- ParallelSnippetGenerator.h ------------------------------*- C++ -*-===//
Clement Courbetac74acd2018-04-04 11:37:06 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Courbetac74acd2018-04-04 11:37:06 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
Miloš Stojanović24b7b992020-01-17 14:28:54 +010010/// A SnippetGenerator implementation to create parallel instruction snippets.
Clement Courbetac74acd2018-04-04 11:37:06 +000011///
12//===----------------------------------------------------------------------===//
13
Miloš Stojanović24b7b992020-01-17 14:28:54 +010014#ifndef LLVM_TOOLS_LLVM_EXEGESIS_PARALLELSNIPPETGENERATOR_H
15#define LLVM_TOOLS_LLVM_EXEGESIS_PARALLELSNIPPETGENERATOR_H
Clement Courbetac74acd2018-04-04 11:37:06 +000016
Clement Courbetd939f6d2018-09-13 07:40:53 +000017#include "SnippetGenerator.h"
Clement Courbetac74acd2018-04-04 11:37:06 +000018
Fangrui Song32401af2018-10-22 17:10:47 +000019namespace llvm {
Clement Courbetac74acd2018-04-04 11:37:06 +000020namespace exegesis {
21
Miloš Stojanović24b7b992020-01-17 14:28:54 +010022class ParallelSnippetGenerator : public SnippetGenerator {
Clement Courbetac74acd2018-04-04 11:37:06 +000023public:
Clement Courbet2cd0f282019-10-08 14:30:24 +000024 using SnippetGenerator::SnippetGenerator;
Miloš Stojanović24b7b992020-01-17 14:28:54 +010025 ~ParallelSnippetGenerator() override;
Clement Courbetac74acd2018-04-04 11:37:06 +000026
Clement Courbet50cdd562019-10-09 11:58:42 +000027 Expected<std::vector<CodeTemplate>>
Roman Lebedev6030fe02020-02-12 20:54:39 +030028 generateCodeTemplates(InstructionTemplate Variant,
Clement Courbet8ef97e12019-09-27 08:04:10 +000029 const BitVector &ForbiddenRegisters) const override;
Guillaume Chateletc9f727b2018-06-13 13:24:41 +000030
Guillaume Chateletfb943542018-08-01 14:41:45 +000031 static constexpr const size_t kMinNumDifferentAddresses = 6;
32
Clement Courbetac74acd2018-04-04 11:37:06 +000033private:
Guillaume Chateletfb943542018-08-01 14:41:45 +000034 // 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 Chatelet70ac0192018-09-27 09:23:04 +000057 void instantiateMemoryOperands(
58 unsigned ScratchSpaceReg,
59 std::vector<InstructionTemplate> &SnippetTemplate) const;
Clement Courbetac74acd2018-04-04 11:37:06 +000060};
61
Clement Courbetac74acd2018-04-04 11:37:06 +000062} // namespace exegesis
Fangrui Song32401af2018-10-22 17:10:47 +000063} // namespace llvm
Clement Courbetac74acd2018-04-04 11:37:06 +000064
Miloš Stojanović24b7b992020-01-17 14:28:54 +010065#endif // LLVM_TOOLS_LLVM_EXEGESIS_PARALLELSNIPPETGENERATOR_H