1 //===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump Tables --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Nate Begeman and is distributed under the
6 // University of Illinois Open Source 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;
31 /// MachineJumpTableEntry - One jump table in the jump table info.
33 struct MachineJumpTableEntry {
34 /// MBBs - The vector of basic blocks from which to create the jump table.
35 std::vector<MachineBasicBlock*> MBBs;
37 explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M)
41 class MachineJumpTableInfo {
44 std::vector<MachineJumpTableEntry> JumpTables;
46 MachineJumpTableInfo(unsigned Size, unsigned Align)
47 : EntrySize(Size), Alignment(Align) {}
49 /// getJumpTableIndex - Create a new jump table or return an existing one.
51 unsigned getJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
53 /// isEmpty - Return true if there are no jump tables.
55 bool isEmpty() const { return JumpTables.empty(); }
57 const std::vector<MachineJumpTableEntry> &getJumpTables() const {
61 /// RemoveJumpTable - Mark the specific index as being dead. This will cause
62 /// it to not be emitted.
63 void RemoveJumpTable(unsigned Idx) {
64 JumpTables[Idx].MBBs.clear();
67 /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
68 /// the jump tables to branch to New instead.
69 bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New) {
70 assert(Old != New && "Not making a change?");
71 bool MadeChange = false;
72 for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
73 MachineJumpTableEntry &JTE = JumpTables[i];
74 for (unsigned j = 0, e = JTE.MBBs.size(); j != e; ++j)
75 if (JTE.MBBs[j] == Old) {
83 /// getEntrySize - Returns the size of an individual field in a jump table.
85 unsigned getEntrySize() const { return EntrySize; }
87 /// getAlignment - returns the target's preferred alignment for jump tables
88 unsigned getAlignment() const { return Alignment; }
90 /// print - Used by the MachineFunction printer to print information about
91 /// jump tables. Implemented in MachineFunction.cpp
93 void print(std::ostream &OS) const;
94 void print(std::ostream *OS) const { if (OS) print(*OS); }
96 /// dump - Call print(std::cerr) to be called from the debugger.
101 } // End llvm namespace