blob: fcfeabe99ee07a8c9a4b9fae5bdfc31ee3f5def2 [file] [log] [blame]
Clement Courbetac74acd2018-04-04 11:37:06 +00001//===-- Uops.h --------------------------------------------------*- C++ -*-===//
2//
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
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 Courbetd939f6d2018-09-13 07:40:53 +000018#include "SnippetGenerator.h"
Clement Courbetac74acd2018-04-04 11:37:06 +000019
Fangrui Song32401af2018-10-22 17:10:47 +000020namespace llvm {
Clement Courbetac74acd2018-04-04 11:37:06 +000021namespace exegesis {
22
Clement Courbetd939f6d2018-09-13 07:40:53 +000023class UopsSnippetGenerator : public SnippetGenerator {
Clement Courbetac74acd2018-04-04 11:37:06 +000024public:
Clement Courbet2cd0f282019-10-08 14:30:24 +000025 using SnippetGenerator::SnippetGenerator;
Clement Courbetd939f6d2018-09-13 07:40:53 +000026 ~UopsSnippetGenerator() override;
Clement Courbetac74acd2018-04-04 11:37:06 +000027
Guillaume Chatelet296a8622018-10-15 09:09:19 +000028 llvm::Expected<std::vector<CodeTemplate>>
Clement Courbet8ef97e12019-09-27 08:04:10 +000029 generateCodeTemplates(const Instruction &Instr,
30 const BitVector &ForbiddenRegisters) const override;
Guillaume Chateletc9f727b2018-06-13 13:24:41 +000031
Guillaume Chateletfb943542018-08-01 14:41:45 +000032 static constexpr const size_t kMinNumDifferentAddresses = 6;
33
Clement Courbetac74acd2018-04-04 11:37:06 +000034private:
Guillaume Chateletfb943542018-08-01 14:41:45 +000035 // 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 Chatelet70ac0192018-09-27 09:23:04 +000058 void instantiateMemoryOperands(
59 unsigned ScratchSpaceReg,
60 std::vector<InstructionTemplate> &SnippetTemplate) const;
Clement Courbetac74acd2018-04-04 11:37:06 +000061};
62
Clement Courbetd939f6d2018-09-13 07:40:53 +000063class UopsBenchmarkRunner : public BenchmarkRunner {
64public:
65 UopsBenchmarkRunner(const LLVMState &State)
66 : BenchmarkRunner(State, InstructionBenchmark::Uops) {}
67 ~UopsBenchmarkRunner() override;
68
69 static constexpr const size_t kMinNumDifferentAddresses = 6;
70
71private:
Clement Courbetf973c2d2018-10-17 15:04:15 +000072 llvm::Expected<std::vector<BenchmarkMeasure>>
73 runMeasurements(const FunctionExecutor &Executor) const override;
Clement Courbetd939f6d2018-09-13 07:40:53 +000074};
75
Clement Courbetac74acd2018-04-04 11:37:06 +000076} // namespace exegesis
Fangrui Song32401af2018-10-22 17:10:47 +000077} // namespace llvm
Clement Courbetac74acd2018-04-04 11:37:06 +000078
79#endif // LLVM_TOOLS_LLVM_EXEGESIS_UOPS_H