convert some stuff to work on raw_ostreams instead of std::ostream.
[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 <cassert>
25
26 namespace llvm {
27
28 class MachineBasicBlock;
29 class TargetData;
30 class raw_ostream;
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
72   /// getEntrySize - Returns the size of an individual field in a jump table. 
73   ///
74   unsigned getEntrySize() const { return EntrySize; }
75   
76   /// getAlignment - returns the target's preferred alignment for jump tables
77   unsigned getAlignment() const { return Alignment; }
78   
79   /// print - Used by the MachineFunction printer to print information about
80   /// jump tables.  Implemented in MachineFunction.cpp
81   ///
82   void print(raw_ostream &OS) const;
83
84   /// dump - Call to stderr.
85   ///
86   void dump() const;
87 };
88
89 } // End llvm namespace
90
91 #endif