LLVM 20.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
23#include <cassert>
24#include <vector>
25
26namespace llvm {
27
28class MachineBasicBlock;
29class DataLayout;
30class 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 /// The hotness of MJTE is inferred from the hotness of the source basic
40 /// block(s) that reference it.
42
43 explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock *> &M);
44};
45
47public:
48 /// JTEntryKind - This enum indicates how each entry of the jump table is
49 /// represented and emitted.
51 /// EK_BlockAddress - Each entry is a plain address of block, e.g.:
52 /// .word LBB123
54
55 /// EK_GPRel64BlockAddress - Each entry is an address of block, encoded
56 /// with a relocation as gp-relative, e.g.:
57 /// .gpdword LBB123
59
60 /// EK_GPRel32BlockAddress - Each entry is an address of block, encoded
61 /// with a relocation as gp-relative, e.g.:
62 /// .gprel32 LBB123
64
65 /// EK_LabelDifference32 - Each entry is the address of the block minus
66 /// the address of the jump table. This is used for PIC jump tables where
67 /// gprel32 is not supported. e.g.:
68 /// .word LBB123 - LJTI1_2
69 /// If the .set directive is supported, this is emitted as:
70 /// .set L4_5_set_123, LBB123 - LJTI1_2
71 /// .word L4_5_set_123
73
74 /// EK_LabelDifference64 - Each entry is the address of the block minus
75 /// the address of the jump table. This is used for PIC jump tables where
76 /// gprel64 is not supported. e.g.:
77 /// .quad LBB123 - LJTI1_2
79
80 /// EK_Inline - Jump table entries are emitted inline at their point of
81 /// use. It is the responsibility of the target to emit the entries.
83
84 /// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the
85 /// TargetLowering::LowerCustomJumpTableEntry hook.
87 };
88
89private:
90 JTEntryKind EntryKind;
91 std::vector<MachineJumpTableEntry> JumpTables;
92public:
93 explicit MachineJumpTableInfo(JTEntryKind Kind): EntryKind(Kind) {}
94
95 JTEntryKind getEntryKind() const { return EntryKind; }
96
97 /// getEntrySize - Return the size of each entry in the jump table.
98 unsigned getEntrySize(const DataLayout &TD) const;
99 /// getEntryAlignment - Return the alignment of each entry in the jump table.
100 unsigned getEntryAlignment(const DataLayout &TD) const;
101
102 /// createJumpTableIndex - Create a new jump table.
103 ///
104 unsigned createJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
105
106 /// isEmpty - Return true if there are no jump tables.
107 ///
108 bool isEmpty() const { return JumpTables.empty(); }
109
110 const std::vector<MachineJumpTableEntry> &getJumpTables() const {
111 return JumpTables;
112 }
113
114 // Update machine jump table entry's hotness. Return true if the hotness is
115 // updated.
116 bool updateJumpTableEntryHotness(size_t JTI,
118
119 /// RemoveJumpTable - Mark the specific index as being dead. This will
120 /// prevent it from being emitted.
121 void RemoveJumpTable(unsigned Idx) {
122 JumpTables[Idx].MBBs.clear();
123 }
124
125 /// RemoveMBBFromJumpTables - If MBB is present in any jump tables, remove it.
127
128 /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
129 /// the jump tables to branch to New instead.
131
132 /// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update
133 /// the jump table to branch to New instead.
134 bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old,
135 MachineBasicBlock *New);
136
137 /// print - Used by the MachineFunction printer to print information about
138 /// jump tables. Implemented in MachineFunction.cpp
139 ///
140 void print(raw_ostream &OS) const;
141
142 /// dump - Call to stderr.
143 ///
144 void dump() const;
145};
146
147
148/// Prints a jump table entry reference.
149///
150/// The format is:
151/// %jump-table.5 - a jump table entry with index == 5.
152///
153/// Usage: OS << printJumpTableEntryReference(Idx) << '\n';
154Printable printJumpTableEntryReference(unsigned Idx);
155
156} // End llvm namespace
157
158#endif
MachineBasicBlock & MBB
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
bool RemoveMBBFromJumpTables(MachineBasicBlock *MBB)
RemoveMBBFromJumpTables - If MBB is present in any jump tables, remove it.
bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New)
ReplaceMBBInJumpTables - If Old is the target of any jump tables, update the jump tables to branch to...
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.
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.
unsigned createJumpTableIndex(const std::vector< MachineBasicBlock * > &DestBBs)
createJumpTableIndex - Create a new jump table.
void dump() const
dump - Call to stderr.
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...
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,...
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:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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.