1
//===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump Tables --*- C++ -*-===//
3
// The LLVM Compiler Infrastructure
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
8
//===----------------------------------------------------------------------===//
10
// The MachineJumpTableInfo class keeps track of jump tables referenced by
11
// lowered switch instructions in the MachineFunction.
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.
18
//===----------------------------------------------------------------------===//
20
#ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
21
#define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
28
class MachineBasicBlock;
32
/// MachineJumpTableEntry - One jump table in the jump table info.
34
struct MachineJumpTableEntry {
35
/// MBBs - The vector of basic blocks from which to create the jump table.
36
std::vector<MachineBasicBlock*> MBBs;
38
explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M)
42
class MachineJumpTableInfo {
44
/// JTEntryKind - This enum indicates how each entry of the jump table is
45
/// represented and emitted.
47
/// EK_BlockAddress - Each entry is a plain address of block, e.g.:
51
/// EK_GPRel64BlockAddress - Each entry is an address of block, encoded
52
/// with a relocation as gp-relative, e.g.:
54
EK_GPRel64BlockAddress,
56
/// EK_GPRel32BlockAddress - Each entry is an address of block, encoded
57
/// with a relocation as gp-relative, e.g.:
59
EK_GPRel32BlockAddress,
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
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.
74
/// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the
75
/// TargetLowering::LowerCustomJumpTableEntry hook.
79
JTEntryKind EntryKind;
80
std::vector<MachineJumpTableEntry> JumpTables;
82
explicit MachineJumpTableInfo(JTEntryKind Kind): EntryKind(Kind) {}
84
JTEntryKind getEntryKind() const { return EntryKind; }
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;
91
/// createJumpTableIndex - Create a new jump table.
93
unsigned createJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
95
/// isEmpty - Return true if there are no jump tables.
97
bool isEmpty() const { return JumpTables.empty(); }
99
const std::vector<MachineJumpTableEntry> &getJumpTables() const {
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();
109
/// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
110
/// the jump tables to branch to New instead.
111
bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New);
113
/// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update
114
/// the jump table to branch to New instead.
115
bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old,
116
MachineBasicBlock *New);
118
/// print - Used by the MachineFunction printer to print information about
119
/// jump tables. Implemented in MachineFunction.cpp
121
void print(raw_ostream &OS) const;
123
/// dump - Call to stderr.
128
} // End llvm namespace