LLVM  14.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 
22 #include "llvm/Support/Printable.h"
23 #include <cassert>
24 #include <vector>
25 
26 namespace llvm {
27 
28 class MachineBasicBlock;
29 class DataLayout;
30 class raw_ostream;
31 
32 /// MachineJumpTableEntry - One jump table in the jump table info.
33 ///
35  /// MBBs - The vector of basic blocks from which to create the jump table.
36  std::vector<MachineBasicBlock*> MBBs;
37 
38  explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M)
39  : MBBs(M) {}
40 };
41 
43 public:
44  /// JTEntryKind - This enum indicates how each entry of the jump table is
45  /// represented and emitted.
46  enum JTEntryKind {
47  /// EK_BlockAddress - Each entry is a plain address of block, e.g.:
48  /// .word LBB123
50 
51  /// EK_GPRel64BlockAddress - Each entry is an address of block, encoded
52  /// with a relocation as gp-relative, e.g.:
53  /// .gpdword LBB123
55 
56  /// EK_GPRel32BlockAddress - Each entry is an address of block, encoded
57  /// with a relocation as gp-relative, e.g.:
58  /// .gprel32 LBB123
60 
61  /// EK_LabelDifference32 - Each entry is the address of the block minus
62  /// the address of the jump table. This is used for PIC jump tables where
63  /// gprel32 is not supported. e.g.:
64  /// .word LBB123 - LJTI1_2
65  /// If the .set directive is supported, this is emitted as:
66  /// .set L4_5_set_123, LBB123 - LJTI1_2
67  /// .word L4_5_set_123
69 
70  /// EK_Inline - Jump table entries are emitted inline at their point of
71  /// use. It is the responsibility of the target to emit the entries.
73 
74  /// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the
75  /// TargetLowering::LowerCustomJumpTableEntry hook.
77  };
78 private:
79  JTEntryKind EntryKind;
80  std::vector<MachineJumpTableEntry> JumpTables;
81 public:
82  explicit MachineJumpTableInfo(JTEntryKind Kind): EntryKind(Kind) {}
83 
84  JTEntryKind getEntryKind() const { return EntryKind; }
85 
86  /// getEntrySize - Return the size of each entry in the jump table.
87  unsigned getEntrySize(const DataLayout &TD) const;
88  /// getEntryAlignment - Return the alignment of each entry in the jump table.
89  unsigned getEntryAlignment(const DataLayout &TD) const;
90 
91  /// createJumpTableIndex - Create a new jump table.
92  ///
93  unsigned createJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
94 
95  /// isEmpty - Return true if there are no jump tables.
96  ///
97  bool isEmpty() const { return JumpTables.empty(); }
98 
99  const std::vector<MachineJumpTableEntry> &getJumpTables() const {
100  return JumpTables;
101  }
102 
103  /// RemoveJumpTable - Mark the specific index as being dead. This will
104  /// prevent it from being emitted.
105  void RemoveJumpTable(unsigned Idx) {
106  JumpTables[Idx].MBBs.clear();
107  }
108 
109  /// RemoveMBBFromJumpTables - If MBB is present in any jump tables, remove it.
111 
112  /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
113  /// the jump tables to branch to New instead.
115 
116  /// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update
117  /// the jump table to branch to New instead.
118  bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old,
119  MachineBasicBlock *New);
120 
121  /// print - Used by the MachineFunction printer to print information about
122  /// jump tables. Implemented in MachineFunction.cpp
123  ///
124  void print(raw_ostream &OS) const;
125 
126  /// dump - Call to stderr.
127  ///
128  void dump() const;
129 };
130 
131 
132 /// Prints a jump table entry reference.
133 ///
134 /// The format is:
135 /// %jump-table.5 - a jump table entry with index == 5.
136 ///
137 /// Usage: OS << printJumpTableEntryReference(Idx) << '\n';
138 Printable printJumpTableEntryReference(unsigned Idx);
139 
140 } // End llvm namespace
141 
142 #endif
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::MachineJumpTableInfo::RemoveMBBFromJumpTables
bool RemoveMBBFromJumpTables(MachineBasicBlock *MBB)
RemoveMBBFromJumpTables - If MBB is present in any jump tables, remove it.
Definition: MachineFunction.cpp:1307
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::MachineJumpTableInfo::createJumpTableIndex
unsigned createJumpTableIndex(const std::vector< MachineBasicBlock * > &DestBBs)
createJumpTableIndex - Create a new jump table.
Definition: MachineFunction.cpp:1288
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::MachineJumpTableEntry::MachineJumpTableEntry
MachineJumpTableEntry(const std::vector< MachineBasicBlock * > &M)
Definition: MachineJumpTableInfo.h:38
Printable.h
llvm::MachineJumpTableInfo::EK_BlockAddress
@ EK_BlockAddress
EK_BlockAddress - Each entry is a plain address of block, e.g.
Definition: MachineJumpTableInfo.h:49
llvm::MachineJumpTableInfo::EK_Custom32
@ EK_Custom32
EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the TargetLowering::LowerCustomJ...
Definition: MachineJumpTableInfo.h:76
llvm::MachineJumpTableInfo::getEntrySize
unsigned getEntrySize(const DataLayout &TD) const
getEntrySize - Return the size of each entry in the jump table.
Definition: MachineFunction.cpp:1249
llvm::MachineJumpTableInfo::ReplaceMBBInJumpTables
bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New)
ReplaceMBBInJumpTables - If Old is the target of any jump tables, update the jump tables to branch to...
Definition: MachineFunction.cpp:1297
llvm::MachineJumpTableInfo::getEntryKind
JTEntryKind getEntryKind() const
Definition: MachineJumpTableInfo.h:84
llvm::MachineJumpTableInfo::dump
void dump() const
dump - Call to stderr.
Definition: MachineFunction.cpp:1350
llvm::MachineJumpTableInfo::isEmpty
bool isEmpty() const
isEmpty - Return true if there are no jump tables.
Definition: MachineJumpTableInfo.h:97
llvm::MachineJumpTableEntry::MBBs
std::vector< MachineBasicBlock * > MBBs
MBBs - The vector of basic blocks from which to create the jump table.
Definition: MachineJumpTableInfo.h:36
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MachineJumpTableInfo::MachineJumpTableInfo
MachineJumpTableInfo(JTEntryKind Kind)
Definition: MachineJumpTableInfo.h:82
llvm::printJumpTableEntryReference
Printable printJumpTableEntryReference(unsigned Idx)
Prints a jump table entry reference.
Definition: MachineFunction.cpp:1353
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineJumpTableInfo::EK_LabelDifference32
@ EK_LabelDifference32
EK_LabelDifference32 - Each entry is the address of the block minus the address of the jump table.
Definition: MachineJumpTableInfo.h:68
llvm::MachineJumpTableInfo::getJumpTables
const std::vector< MachineJumpTableEntry > & getJumpTables() const
Definition: MachineJumpTableInfo.h:99
llvm::MachineJumpTableInfo::EK_GPRel64BlockAddress
@ EK_GPRel64BlockAddress
EK_GPRel64BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
Definition: MachineJumpTableInfo.h:54
llvm::MachineJumpTableInfo::JTEntryKind
JTEntryKind
JTEntryKind - This enum indicates how each entry of the jump table is represented and emitted.
Definition: MachineJumpTableInfo.h:46
llvm::MachineJumpTableInfo::print
void print(raw_ostream &OS) const
print - Used by the MachineFunction printer to print information about jump tables.
Definition: MachineFunction.cpp:1333
llvm::MachineJumpTableInfo::ReplaceMBBInJumpTable
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...
Definition: MachineFunction.cpp:1319
llvm::MachineJumpTableInfo::RemoveJumpTable
void RemoveJumpTable(unsigned Idx)
RemoveJumpTable - Mark the specific index as being dead.
Definition: MachineJumpTableInfo.h:105
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::MachineJumpTableInfo::EK_Inline
@ EK_Inline
EK_Inline - Jump table entries are emitted inline at their point of use.
Definition: MachineJumpTableInfo.h:72
llvm::MachineJumpTableEntry
MachineJumpTableEntry - One jump table in the jump table info.
Definition: MachineJumpTableInfo.h:34
llvm::MachineJumpTableInfo::EK_GPRel32BlockAddress
@ EK_GPRel32BlockAddress
EK_GPRel32BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
Definition: MachineJumpTableInfo.h:59
llvm::MachineJumpTableInfo::getEntryAlignment
unsigned getEntryAlignment(const DataLayout &TD) const
getEntryAlignment - Return the alignment of each entry in the jump table.
Definition: MachineFunction.cpp:1268
llvm::MachineJumpTableInfo
Definition: MachineJumpTableInfo.h:42