X86InstrFoldTables.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //===-- X86InstrFoldTables.h - X86 Instruction Folding Tables ---*- 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 interface to query the X86 memory folding tables.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_X86_X86INSTRFOLDTABLES_H
  13. #define LLVM_LIB_TARGET_X86_X86INSTRFOLDTABLES_H
  14. #include <cstdint>
  15. namespace llvm {
  16. enum {
  17. // Select which memory operand is being unfolded.
  18. // (stored in bits 0 - 2)
  19. TB_INDEX_0 = 0,
  20. TB_INDEX_1 = 1,
  21. TB_INDEX_2 = 2,
  22. TB_INDEX_3 = 3,
  23. TB_INDEX_4 = 4,
  24. TB_INDEX_MASK = 0x7,
  25. // Do not insert the reverse map (MemOp -> RegOp) into the table.
  26. // This may be needed because there is a many -> one mapping.
  27. TB_NO_REVERSE = 1 << 3,
  28. // Do not insert the forward map (RegOp -> MemOp) into the table.
  29. // This is needed for Native Client, which prohibits branch
  30. // instructions from using a memory operand.
  31. TB_NO_FORWARD = 1 << 4,
  32. TB_FOLDED_LOAD = 1 << 5,
  33. TB_FOLDED_STORE = 1 << 6,
  34. TB_FOLDED_BCAST = 1 << 7,
  35. // Minimum alignment required for load/store.
  36. // Used for RegOp->MemOp conversion. Encoded as Log2(Align) + 1 to allow 0
  37. // to mean align of 0.
  38. // (stored in bits 8 - 11)
  39. TB_ALIGN_SHIFT = 8,
  40. TB_ALIGN_NONE = 0 << TB_ALIGN_SHIFT,
  41. TB_ALIGN_16 = 5 << TB_ALIGN_SHIFT,
  42. TB_ALIGN_32 = 6 << TB_ALIGN_SHIFT,
  43. TB_ALIGN_64 = 7 << TB_ALIGN_SHIFT,
  44. TB_ALIGN_MASK = 0xf << TB_ALIGN_SHIFT,
  45. // Broadcast type.
  46. // (stored in bits 12 - 13)
  47. TB_BCAST_TYPE_SHIFT = 12,
  48. TB_BCAST_D = 0 << TB_BCAST_TYPE_SHIFT,
  49. TB_BCAST_Q = 1 << TB_BCAST_TYPE_SHIFT,
  50. TB_BCAST_SS = 2 << TB_BCAST_TYPE_SHIFT,
  51. TB_BCAST_SD = 3 << TB_BCAST_TYPE_SHIFT,
  52. TB_BCAST_MASK = 0x3 << TB_BCAST_TYPE_SHIFT,
  53. // Unused bits 14-15
  54. };
  55. // This struct is used for both the folding and unfold tables. They KeyOp
  56. // is used to determine the sorting order.
  57. struct X86MemoryFoldTableEntry {
  58. uint16_t KeyOp;
  59. uint16_t DstOp;
  60. uint16_t Flags;
  61. bool operator<(const X86MemoryFoldTableEntry &RHS) const {
  62. return KeyOp < RHS.KeyOp;
  63. }
  64. bool operator==(const X86MemoryFoldTableEntry &RHS) const {
  65. return KeyOp == RHS.KeyOp;
  66. }
  67. friend bool operator<(const X86MemoryFoldTableEntry &TE, unsigned Opcode) {
  68. return TE.KeyOp < Opcode;
  69. }
  70. };
  71. // Look up the memory folding table entry for folding a load and a store into
  72. // operand 0.
  73. const X86MemoryFoldTableEntry *lookupTwoAddrFoldTable(unsigned RegOp);
  74. // Look up the memory folding table entry for folding a load or store with
  75. // operand OpNum.
  76. const X86MemoryFoldTableEntry *lookupFoldTable(unsigned RegOp, unsigned OpNum);
  77. // Look up the memory unfolding table entry for this instruction.
  78. const X86MemoryFoldTableEntry *lookupUnfoldTable(unsigned MemOp);
  79. } // namespace llvm
  80. #endif