Rename MachineInstr::getInstrDescriptor -> getDesc(), which reflects
[oota-llvm.git] / include / llvm / CodeGen / MachineJumpTableInfo.h
1 //===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump Tables  --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // The MachineJumpTableInfo class keeps track of jump tables referenced by
11 // lowered switch instructions in the MachineFunction.
12 //
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.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
21 #define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
22
23 #include <vector>
24 #include <iosfwd>
25 #include <cassert>
26
27 namespace llvm {
28
29 class MachineBasicBlock;
30 class TargetData;
31
32 /// MachineJumpTableEntry - One jump table in the jump table info.
33 ///
34 struct MachineJumpTableEntry {
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   
42 class MachineJumpTableInfo {
43   unsigned EntrySize;
44   unsigned Alignment;
45   std::vector<MachineJumpTableEntry> JumpTables;
46 public:
47   MachineJumpTableInfo(unsigned Size, unsigned Align)
48   : EntrySize(Size), Alignment(Align) {}
49     
50   /// getJumpTableIndex - Create a new jump table or return an existing one.
51   ///
52   unsigned getJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
53   
54   /// isEmpty - Return true if there are no jump tables.
55   ///
56   bool isEmpty() const { return JumpTables.empty(); }
57
58   const std::vector<MachineJumpTableEntry> &getJumpTables() const {
59     return JumpTables;
60   }
61   
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();
66   }
67   
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) {
71     assert(Old != New && "Not making a change?");
72     bool MadeChange = false;
73     for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
74       MachineJumpTableEntry &JTE = JumpTables[i];
75       for (unsigned j = 0, e = JTE.MBBs.size(); j != e; ++j)
76         if (JTE.MBBs[j] == Old) {
77           JTE.MBBs[j] = New;
78           MadeChange = true;
79         }
80     }
81     return MadeChange;
82   }
83   
84   /// getEntrySize - Returns the size of an individual field in a jump table. 
85   ///
86   unsigned getEntrySize() const { return EntrySize; }
87   
88   /// getAlignment - returns the target's preferred alignment for jump tables
89   unsigned getAlignment() const { return Alignment; }
90   
91   /// print - Used by the MachineFunction printer to print information about
92   /// jump tables.  Implemented in MachineFunction.cpp
93   ///
94   void print(std::ostream &OS) const;
95   void print(std::ostream *OS) const { if (OS) print(*OS); }
96
97   /// dump - Call print(std::cerr) to be called from the debugger.
98   ///
99   void dump() const;
100 };
101
102 } // End llvm namespace
103
104 #endif