ParallelSnippetGenerator.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===-- ParallelSnippetGenerator.h ------------------------------*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. ///
  9. /// \file
  10. /// A SnippetGenerator implementation to create parallel instruction snippets.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_TOOLS_LLVM_EXEGESIS_PARALLELSNIPPETGENERATOR_H
  14. #define LLVM_TOOLS_LLVM_EXEGESIS_PARALLELSNIPPETGENERATOR_H
  15. #include "SnippetGenerator.h"
  16. namespace llvm {
  17. namespace exegesis {
  18. class ParallelSnippetGenerator : public SnippetGenerator {
  19. public:
  20. using SnippetGenerator::SnippetGenerator;
  21. ~ParallelSnippetGenerator() override;
  22. Expected<std::vector<CodeTemplate>>
  23. generateCodeTemplates(InstructionTemplate Variant,
  24. const BitVector &ForbiddenRegisters) const override;
  25. static constexpr const size_t kMinNumDifferentAddresses = 6;
  26. private:
  27. // Instantiates memory operands within a snippet.
  28. // To make computations as parallel as possible, we generate independant
  29. // memory locations for instructions that load and store. If there are less
  30. // than kMinNumDifferentAddresses in the original snippet, we duplicate
  31. // instructions until there are this number of instructions.
  32. // For example, assuming kMinNumDifferentAddresses=5 and
  33. // getMaxMemoryAccessSize()=64, if the original snippet is:
  34. // mov eax, [memory]
  35. // we might generate:
  36. // mov eax, [rdi]
  37. // mov eax, [rdi + 64]
  38. // mov eax, [rdi + 128]
  39. // mov eax, [rdi + 192]
  40. // mov eax, [rdi + 256]
  41. // If the original snippet is:
  42. // mov eax, [memory]
  43. // add eax, [memory]
  44. // we might generate:
  45. // mov eax, [rdi]
  46. // add eax, [rdi + 64]
  47. // mov eax, [rdi + 128]
  48. // add eax, [rdi + 192]
  49. // mov eax, [rdi + 256]
  50. void instantiateMemoryOperands(
  51. unsigned ScratchSpaceReg,
  52. std::vector<InstructionTemplate> &SnippetTemplate) const;
  53. };
  54. } // namespace exegesis
  55. } // namespace llvm
  56. #endif // LLVM_TOOLS_LLVM_EXEGESIS_PARALLELSNIPPETGENERATOR_H