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
29 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 {
45 std::vector<MachineJumpTableEntry> JumpTables;
47 MachineJumpTableInfo(unsigned Size, unsigned Align)
48 : EntrySize(Size), Alignment(Align) {}
50 /// getJumpTableIndex - Create a new jump table or return an existing one.
52 unsigned getJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
54 /// isEmpty - Return true if there are no jump tables.
56 bool isEmpty() const { return JumpTables.empty(); }
58 const std::vector<MachineJumpTableEntry> &getJumpTables() const {
62 /// RemoveJumpTable - Mark the specific index as being dead. This will cause
63 /// it to not be emitted.
64 void RemoveJumpTable(unsigned Idx) {
65 JumpTables[Idx].MBBs.clear();
68 /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
69 /// the jump tables to branch to New instead.
70 bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New);
72 /// getEntrySize - Returns the size of an individual field in a jump table.
74 unsigned getEntrySize() const { return EntrySize; }
76 /// getAlignment - returns the target's preferred alignment for jump tables
77 unsigned getAlignment() const { return Alignment; }
79 /// print - Used by the MachineFunction printer to print information about
80 /// jump tables. Implemented in MachineFunction.cpp
82 void print(std::ostream &OS) const;
83 void print(std::ostream *OS) const { if (OS) print(*OS); }
85 /// dump - Call to stderr.
90 } // End llvm namespace