X86InstrFMA3Info.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //===- X86InstrFMA3Info.h - X86 FMA3 Instruction Information ----*- 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. // This file contains the implementation of the classes providing information
  10. // about existing X86 FMA3 opcodes, classifying and grouping them.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H
  14. #define LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H
  15. #include <cstdint>
  16. namespace llvm {
  17. /// This class is used to group {132, 213, 231} forms of FMA opcodes together.
  18. /// Each of the groups has either 3 opcodes, Also, each group has an attributes
  19. /// field describing it.
  20. struct X86InstrFMA3Group {
  21. /// An array holding 3 forms of FMA opcodes.
  22. uint16_t Opcodes[3];
  23. /// This bitfield specifies the attributes associated with the created
  24. /// FMA groups of opcodes.
  25. uint16_t Attributes;
  26. enum {
  27. Form132,
  28. Form213,
  29. Form231,
  30. };
  31. enum : uint16_t {
  32. /// This bit must be set in the 'Attributes' field of FMA group if such
  33. /// group of FMA opcodes consists of FMA intrinsic opcodes.
  34. Intrinsic = 0x1,
  35. /// This bit must be set in the 'Attributes' field of FMA group if such
  36. /// group of FMA opcodes consists of AVX512 opcodes accepting a k-mask and
  37. /// passing the elements from the 1st operand to the result of the operation
  38. /// when the correpondings bits in the k-mask are unset.
  39. KMergeMasked = 0x2,
  40. /// This bit must be set in the 'Attributes' field of FMA group if such
  41. /// group of FMA opcodes consists of AVX512 opcodes accepting a k-zeromask.
  42. KZeroMasked = 0x4,
  43. };
  44. /// Returns the 132 form of FMA opcode.
  45. unsigned get132Opcode() const {
  46. return Opcodes[Form132];
  47. }
  48. /// Returns the 213 form of FMA opcode.
  49. unsigned get213Opcode() const {
  50. return Opcodes[Form213];
  51. }
  52. /// Returns the 231 form of FMA opcode.
  53. unsigned get231Opcode() const {
  54. return Opcodes[Form231];
  55. }
  56. /// Returns true iff the group of FMA opcodes holds intrinsic opcodes.
  57. bool isIntrinsic() const { return (Attributes & Intrinsic) != 0; }
  58. /// Returns true iff the group of FMA opcodes holds k-merge-masked opcodes.
  59. bool isKMergeMasked() const {
  60. return (Attributes & KMergeMasked) != 0;
  61. }
  62. /// Returns true iff the group of FMA opcodes holds k-zero-masked opcodes.
  63. bool isKZeroMasked() const { return (Attributes &KZeroMasked) != 0; }
  64. /// Returns true iff the group of FMA opcodes holds any of k-masked opcodes.
  65. bool isKMasked() const {
  66. return (Attributes & (KMergeMasked | KZeroMasked)) != 0;
  67. }
  68. bool operator<(const X86InstrFMA3Group &RHS) const {
  69. return Opcodes[0] < RHS.Opcodes[0];
  70. }
  71. };
  72. /// Returns a reference to a group of FMA3 opcodes to where the given
  73. /// \p Opcode is included. If the given \p Opcode is not recognized as FMA3
  74. /// and not included into any FMA3 group, then nullptr is returned.
  75. const X86InstrFMA3Group *getFMA3Group(unsigned Opcode, uint64_t TSFlags);
  76. } // end namespace llvm
  77. #endif // LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H