1 //===-- Uops.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 /// A BenchmarkRunner implementation to measure uop decomposition.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_UOPS_H
16 #define LLVM_TOOLS_LLVM_EXEGESIS_UOPS_H
17 
18 #include "BenchmarkRunner.h"
19 #include "SnippetGenerator.h"
20 
21 namespace llvm {
22 namespace exegesis {
23 
24 class UopsSnippetGenerator : public SnippetGenerator {
25 public:
UopsSnippetGenerator(const LLVMState & State)26   UopsSnippetGenerator(const LLVMState &State) : SnippetGenerator(State) {}
27   ~UopsSnippetGenerator() override;
28 
29   llvm::Expected<std::vector<CodeTemplate>>
30   generateCodeTemplates(const Instruction &Instr) const override;
31 
32   static constexpr const size_t kMinNumDifferentAddresses = 6;
33 
34 private:
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]
58   void instantiateMemoryOperands(
59       unsigned ScratchSpaceReg,
60       std::vector<InstructionTemplate> &SnippetTemplate) const;
61 };
62 
63 class UopsBenchmarkRunner : public BenchmarkRunner {
64 public:
UopsBenchmarkRunner(const LLVMState & State)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:
72   llvm::Expected<std::vector<BenchmarkMeasure>>
73   runMeasurements(const FunctionExecutor &Executor) const override;
74 };
75 
76 } // namespace exegesis
77 } // namespace llvm
78 
79 #endif // LLVM_TOOLS_LLVM_EXEGESIS_UOPS_H
80