LLVM 22.0.0git
MachineJumpTableInfo.h
Go to the documentation of this file.
1//===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump 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// The MachineJumpTableInfo class keeps track of jump tables referenced by
10// lowered switch instructions in the MachineFunction.
11//
12// Instructions reference the address of these jump tables through the use of
13// MO_JumpTableIndex values. When emitting assembly or machine code, these
14// virtual address references are converted to refer to the address of the
15// function jump tables.
16//
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
20#define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
21
24#include <cassert>
25#include <vector>
26
27namespace llvm {
28
29class MachineBasicBlock;
30class DataLayout;
31class raw_ostream;
33
34/// MachineJumpTableEntry - One jump table in the jump table info.
35///
37 /// MBBs - The vector of basic blocks from which to create the jump table.
38 std::vector<MachineBasicBlock*> MBBs;
39
40 /// The hotness of MJTE is inferred from the hotness of the source basic
41 /// block(s) that reference it.
43
45 const std::vector<MachineBasicBlock *> &M);
46};
47
49public:
50 /// JTEntryKind - This enum indicates how each entry of the jump table is
51 /// represented and emitted.
53 /// EK_BlockAddress - Each entry is a plain address of block, e.g.:
54 /// .word LBB123
56
57 /// EK_GPRel64BlockAddress - Each entry is an address of block, encoded
58 /// with a relocation as gp-relative, e.g.:
59 /// .gpdword LBB123
61
62 /// EK_GPRel32BlockAddress - Each entry is an address of block, encoded
63 /// with a relocation as gp-relative, e.g.:
64 /// .gprel32 LBB123
66
67 /// EK_LabelDifference32 - Each entry is the address of the block minus
68 /// the address of the jump table. This is used for PIC jump tables where
69 /// gprel32 is not supported. e.g.:
70 /// .word LBB123 - LJTI1_2
71 /// If the .set directive is supported, this is emitted as:
72 /// .set L4_5_set_123, LBB123 - LJTI1_2
73 /// .word L4_5_set_123
75
76 /// EK_LabelDifference64 - Each entry is the address of the block minus
77 /// the address of the jump table. This is used for PIC jump tables where
78 /// gprel64 is not supported. e.g.:
79 /// .quad LBB123 - LJTI1_2
81
82 /// EK_Inline - Jump table entries are emitted inline at their point of
83 /// use. It is the responsibility of the target to emit the entries.
85
86 /// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the
87 /// TargetLowering::LowerCustomJumpTableEntry hook.
89 };
90
91private:
92 JTEntryKind EntryKind;
93 std::vector<MachineJumpTableEntry> JumpTables;
94public:
95 explicit MachineJumpTableInfo(JTEntryKind Kind): EntryKind(Kind) {}
96
97 JTEntryKind getEntryKind() const { return EntryKind; }
98
99 /// getEntrySize - Return the size of each entry in the jump table.
100 LLVM_ABI unsigned getEntrySize(const DataLayout &TD) const;
101 /// getEntryAlignment - Return the alignment of each entry in the jump table.
102 LLVM_ABI unsigned getEntryAlignment(const DataLayout &TD) const;
103
104 /// createJumpTableIndex - Create a new jump table.
105 ///
106 LLVM_ABI unsigned
107 createJumpTableIndex(const std::vector<MachineBasicBlock *> &DestBBs);
108
109 /// isEmpty - Return true if there are no jump tables.
110 ///
111 bool isEmpty() const { return JumpTables.empty(); }
112
113 const std::vector<MachineJumpTableEntry> &getJumpTables() const {
114 return JumpTables;
115 }
116
117 // Update machine jump table entry's hotness. Return true if the hotness is
118 // updated.
121
122 /// RemoveJumpTable - Mark the specific index as being dead. This will
123 /// prevent it from being emitted.
124 void RemoveJumpTable(unsigned Idx) {
125 JumpTables[Idx].MBBs.clear();
126 }
127
128 /// RemoveMBBFromJumpTables - If MBB is present in any jump tables, remove it.
130
131 /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
132 /// the jump tables to branch to New instead.
134 MachineBasicBlock *New);
135
136 /// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update
137 /// the jump table to branch to New instead.
139 MachineBasicBlock *New);
140
141 /// print - Used by the MachineFunction printer to print information about
142 /// jump tables. Implemented in MachineFunction.cpp
143 ///
144 LLVM_ABI void print(raw_ostream &OS) const;
145
146 /// dump - Call to stderr.
147 ///
148 LLVM_ABI void dump() const;
149};
150
151
152/// Prints a jump table entry reference.
153///
154/// The format is:
155/// %jump-table.5 - a jump table entry with index == 5.
156///
157/// Usage: OS << printJumpTableEntryReference(Idx) << '\n';
158LLVM_ABI Printable printJumpTableEntryReference(unsigned Idx);
159
160} // End llvm namespace
161
162#endif
MachineBasicBlock & MBB
#define LLVM_ABI
Definition: Compiler.h:213
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
raw_pwrite_stream & OS
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
LLVM_ABI bool RemoveMBBFromJumpTables(MachineBasicBlock *MBB)
RemoveMBBFromJumpTables - If MBB is present in any jump tables, remove it.
LLVM_ABI bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New)
ReplaceMBBInJumpTables - If Old is the target of any jump tables, update the jump tables to branch to...
LLVM_ABI void print(raw_ostream &OS) const
print - Used by the MachineFunction printer to print information about jump tables.
void RemoveJumpTable(unsigned Idx)
RemoveJumpTable - Mark the specific index as being dead.
LLVM_ABI unsigned getEntrySize(const DataLayout &TD) const
getEntrySize - Return the size of each entry in the jump table.
bool isEmpty() const
isEmpty - Return true if there are no jump tables.
LLVM_ABI unsigned createJumpTableIndex(const std::vector< MachineBasicBlock * > &DestBBs)
createJumpTableIndex - Create a new jump table.
LLVM_ABI void dump() const
dump - Call to stderr.
LLVM_ABI bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old, MachineBasicBlock *New)
ReplaceMBBInJumpTable - If Old is a target of the jump tables, update the jump table to branch to New...
LLVM_ABI bool updateJumpTableEntryHotness(size_t JTI, MachineFunctionDataHotness Hotness)
MachineJumpTableInfo(JTEntryKind Kind)
JTEntryKind
JTEntryKind - This enum indicates how each entry of the jump table is represented and emitted.
@ EK_GPRel32BlockAddress
EK_GPRel32BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
@ EK_Inline
EK_Inline - Jump table entries are emitted inline at their point of use.
@ EK_LabelDifference32
EK_LabelDifference32 - Each entry is the address of the block minus the address of the jump table.
@ EK_Custom32
EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the TargetLowering::LowerCustomJ...
@ EK_LabelDifference64
EK_LabelDifference64 - Each entry is the address of the block minus the address of the jump table.
@ EK_BlockAddress
EK_BlockAddress - Each entry is a plain address of block, e.g.: .word LBB123.
@ EK_GPRel64BlockAddress
EK_GPRel64BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
LLVM_ABI unsigned getEntryAlignment(const DataLayout &TD) const
getEntryAlignment - Return the alignment of each entry in the jump table.
JTEntryKind getEntryKind() const
const std::vector< MachineJumpTableEntry > & getJumpTables() const
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI Printable printJumpTableEntryReference(unsigned Idx)
Prints a jump table entry reference.
MachineFunctionDataHotness
MachineJumpTableEntry - One jump table in the jump table info.
std::vector< MachineBasicBlock * > MBBs
MBBs - The vector of basic blocks from which to create the jump table.
MachineFunctionDataHotness Hotness
The hotness of MJTE is inferred from the hotness of the source basic block(s) that reference it.