LLVM  8.0.1
MachineJumpTableInfo.h
Go to the documentation of this file.
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 
20 #ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
21 #define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
22 
23 #include "llvm/Support/Printable.h"
24 #include <cassert>
25 #include <vector>
26 
27 namespace llvm {
28 
29 class MachineBasicBlock;
30 class DataLayout;
31 class raw_ostream;
32 
33 /// MachineJumpTableEntry - One jump table in the jump table info.
34 ///
36  /// MBBs - The vector of basic blocks from which to create the jump table.
37  std::vector<MachineBasicBlock*> MBBs;
38 
39  explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M)
40  : MBBs(M) {}
41 };
42 
44 public:
45  /// JTEntryKind - This enum indicates how each entry of the jump table is
46  /// represented and emitted.
47  enum JTEntryKind {
48  /// EK_BlockAddress - Each entry is a plain address of block, e.g.:
49  /// .word LBB123
51 
52  /// EK_GPRel64BlockAddress - Each entry is an address of block, encoded
53  /// with a relocation as gp-relative, e.g.:
54  /// .gpdword LBB123
56 
57  /// EK_GPRel32BlockAddress - Each entry is an address of block, encoded
58  /// with a relocation as gp-relative, e.g.:
59  /// .gprel32 LBB123
61 
62  /// EK_LabelDifference32 - Each entry is the address of the block minus
63  /// the address of the jump table. This is used for PIC jump tables where
64  /// gprel32 is not supported. e.g.:
65  /// .word LBB123 - LJTI1_2
66  /// If the .set directive is supported, this is emitted as:
67  /// .set L4_5_set_123, LBB123 - LJTI1_2
68  /// .word L4_5_set_123
70 
71  /// EK_Inline - Jump table entries are emitted inline at their point of
72  /// use. It is the responsibility of the target to emit the entries.
74 
75  /// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the
76  /// TargetLowering::LowerCustomJumpTableEntry hook.
77  EK_Custom32
78  };
79 private:
80  JTEntryKind EntryKind;
81  std::vector<MachineJumpTableEntry> JumpTables;
82 public:
83  explicit MachineJumpTableInfo(JTEntryKind Kind): EntryKind(Kind) {}
84 
85  JTEntryKind getEntryKind() const { return EntryKind; }
86 
87  /// getEntrySize - Return the size of each entry in the jump table.
88  unsigned getEntrySize(const DataLayout &TD) const;
89  /// getEntryAlignment - Return the alignment of each entry in the jump table.
90  unsigned getEntryAlignment(const DataLayout &TD) const;
91 
92  /// createJumpTableIndex - Create a new jump table.
93  ///
94  unsigned createJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
95 
96  /// isEmpty - Return true if there are no jump tables.
97  ///
98  bool isEmpty() const { return JumpTables.empty(); }
99 
100  const std::vector<MachineJumpTableEntry> &getJumpTables() const {
101  return JumpTables;
102  }
103 
104  /// RemoveJumpTable - Mark the specific index as being dead. This will
105  /// prevent it from being emitted.
106  void RemoveJumpTable(unsigned Idx) {
107  JumpTables[Idx].MBBs.clear();
108  }
109 
110  /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
111  /// the jump tables to branch to New instead.
112  bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New);
113 
114  /// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update
115  /// the jump table to branch to New instead.
116  bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old,
117  MachineBasicBlock *New);
118 
119  /// print - Used by the MachineFunction printer to print information about
120  /// jump tables. Implemented in MachineFunction.cpp
121  ///
122  void print(raw_ostream &OS) const;
123 
124  /// dump - Call to stderr.
125  ///
126  void dump() const;
127 };
128 
129 
130 /// Prints a jump table entry reference.
131 ///
132 /// The format is:
133 /// %jump-table.5 - a jump table entry with index == 5.
134 ///
135 /// Usage: OS << printJumpTableEntryReference(Idx) << '\n';
137 
138 } // End llvm namespace
139 
140 #endif
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
const std::vector< MachineJumpTableEntry > & getJumpTables() const
This class represents lattice values for constants.
Definition: AllocatorList.h:24
EK_Inline - Jump table entries are emitted inline at their point of use.
void RemoveJumpTable(unsigned Idx)
RemoveJumpTable - Mark the specific index as being dead.
JTEntryKind
JTEntryKind - This enum indicates how each entry of the jump table is represented and emitted...
EK_LabelDifference32 - Each entry is the address of the block minus the address of the jump table...
EK_BlockAddress - Each entry is a plain address of block, e.g.
EK_GPRel64BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative...
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
Printable printJumpTableEntryReference(unsigned Idx)
Prints a jump table entry reference.
MachineJumpTableEntry(const std::vector< MachineBasicBlock *> &M)
std::vector< MachineBasicBlock * > MBBs
MBBs - The vector of basic blocks from which to create the jump table.
MachineJumpTableEntry - One jump table in the jump table info.
MachineJumpTableInfo(JTEntryKind Kind)
const unsigned Kind
bool isEmpty() const
isEmpty - Return true if there are no jump tables.
JTEntryKind getEntryKind() const
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
EK_GPRel32BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative...
Simple wrapper around std::function<void(raw_ostream&)>.
Definition: Printable.h:38