Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.4 KiB

  1. //===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump Tables --*- 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. // The MachineJumpTableInfo class keeps track of jump tables referenced by
  11. // lowered switch instructions in the MachineFunction.
  12. //
  13. // Instructions reference the address of these jump tables through the use of
  14. // MO_JumpTableIndex values. When emitting assembly or machine code, these
  15. // virtual address references are converted to refer to the address of the
  16. // function jump tables.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
  20. #define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
  21. #include <cassert>
  22. #include <vector>
  23. namespace llvm {
  24. class MachineBasicBlock;
  25. class DataLayout;
  26. class raw_ostream;
  27. /// MachineJumpTableEntry - One jump table in the jump table info.
  28. ///
  29. struct MachineJumpTableEntry {
  30. /// MBBs - The vector of basic blocks from which to create the jump table.
  31. std::vector<MachineBasicBlock*> MBBs;
  32. explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M)
  33. : MBBs(M) {}
  34. };
  35. class MachineJumpTableInfo {
  36. public:
  37. /// JTEntryKind - This enum indicates how each entry of the jump table is
  38. /// represented and emitted.
  39. enum JTEntryKind {
  40. /// EK_BlockAddress - Each entry is a plain address of block, e.g.:
  41. /// .word LBB123
  42. EK_BlockAddress,
  43. /// EK_GPRel64BlockAddress - Each entry is an address of block, encoded
  44. /// with a relocation as gp-relative, e.g.:
  45. /// .gpdword LBB123
  46. EK_GPRel64BlockAddress,
  47. /// EK_GPRel32BlockAddress - Each entry is an address of block, encoded
  48. /// with a relocation as gp-relative, e.g.:
  49. /// .gprel32 LBB123
  50. EK_GPRel32BlockAddress,
  51. /// EK_LabelDifference32 - Each entry is the address of the block minus
  52. /// the address of the jump table. This is used for PIC jump tables where
  53. /// gprel32 is not supported. e.g.:
  54. /// .word LBB123 - LJTI1_2
  55. /// If the .set directive is supported, this is emitted as:
  56. /// .set L4_5_set_123, LBB123 - LJTI1_2
  57. /// .word L4_5_set_123
  58. EK_LabelDifference32,
  59. /// EK_Inline - Jump table entries are emitted inline at their point of
  60. /// use. It is the responsibility of the target to emit the entries.
  61. EK_Inline,
  62. /// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the
  63. /// TargetLowering::LowerCustomJumpTableEntry hook.
  64. EK_Custom32
  65. };
  66. private:
  67. JTEntryKind EntryKind;
  68. std::vector<MachineJumpTableEntry> JumpTables;
  69. public:
  70. explicit MachineJumpTableInfo(JTEntryKind Kind): EntryKind(Kind) {}
  71. JTEntryKind getEntryKind() const { return EntryKind; }
  72. /// getEntrySize - Return the size of each entry in the jump table.
  73. unsigned getEntrySize(const DataLayout &TD) const;
  74. /// getEntryAlignment - Return the alignment of each entry in the jump table.
  75. unsigned getEntryAlignment(const DataLayout &TD) const;
  76. /// createJumpTableIndex - Create a new jump table.
  77. ///
  78. unsigned createJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
  79. /// isEmpty - Return true if there are no jump tables.
  80. ///
  81. bool isEmpty() const { return JumpTables.empty(); }
  82. const std::vector<MachineJumpTableEntry> &getJumpTables() const {
  83. return JumpTables;
  84. }
  85. /// RemoveJumpTable - Mark the specific index as being dead. This will
  86. /// prevent it from being emitted.
  87. void RemoveJumpTable(unsigned Idx) {
  88. JumpTables[Idx].MBBs.clear();
  89. }
  90. /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
  91. /// the jump tables to branch to New instead.
  92. bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New);
  93. /// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update
  94. /// the jump table to branch to New instead.
  95. bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old,
  96. MachineBasicBlock *New);
  97. /// print - Used by the MachineFunction printer to print information about
  98. /// jump tables. Implemented in MachineFunction.cpp
  99. ///
  100. void print(raw_ostream &OS) const;
  101. /// dump - Call to stderr.
  102. ///
  103. void dump() const;
  104. };
  105. } // End llvm namespace
  106. #endif