More cleanups for MachineOperand:
[oota-llvm.git] / include / llvm / CodeGen / MachineJumpTableInfo.h
index 7f6c965d7cd22c3919994ee4e0afccde96c8bb56..bccd65dfbd060e331b29a67b4cb4fb3f4d1ba65e 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Nate Begeman and is distributed under the
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -22,6 +22,7 @@
 
 #include <vector>
 #include <iosfwd>
+#include <cassert>
 
 namespace llvm {
 
@@ -34,18 +35,21 @@ struct MachineJumpTableEntry {
   /// MBBs - The vector of basic blocks from which to create the jump table.
   std::vector<MachineBasicBlock*> MBBs;
   
-  MachineJumpTableEntry(std::vector<MachineBasicBlock*> &M) : MBBs(M) {}
+  explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M)
+  : MBBs(M) {}
 };
   
 class MachineJumpTableInfo {
-  const TargetData *TD;
+  unsigned EntrySize;
+  unsigned Alignment;
   std::vector<MachineJumpTableEntry> JumpTables;
 public:
-  MachineJumpTableInfo(const TargetData *td) : TD(td) {}
+  MachineJumpTableInfo(unsigned Size, unsigned Align)
+  : EntrySize(Size), Alignment(Align) {}
     
   /// getJumpTableIndex - Create a new jump table or return an existing one.
   ///
-  unsigned getJumpTableIndex(std::vector<MachineBasicBlock*> &DestBBs);
+  unsigned getJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
   
   /// isEmpty - Return true if there are no jump tables.
   ///
@@ -55,27 +59,40 @@ public:
     return JumpTables;
   }
   
+  /// RemoveJumpTable - Mark the specific index as being dead.  This will cause
+  /// it to not be emitted.
+  void RemoveJumpTable(unsigned Idx) {
+    JumpTables[Idx].MBBs.clear();
+  }
+  
   /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
   /// the jump tables to branch to New instead.
-  void ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New) {
+  bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New) {
+    assert(Old != New && "Not making a change?");
+    bool MadeChange = false;
     for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
       MachineJumpTableEntry &JTE = JumpTables[i];
       for (unsigned j = 0, e = JTE.MBBs.size(); j != e; ++j)
-        if (JTE.MBBs[j] == Old)
+        if (JTE.MBBs[j] == Old) {
           JTE.MBBs[j] = New;
+          MadeChange = true;
+        }
     }
+    return MadeChange;
   }
   
-  /// getEntrySize - returns the size of an individual field in a jump table 
-  unsigned getEntrySize() const;
+  /// getEntrySize - Returns the size of an individual field in a jump table. 
+  ///
+  unsigned getEntrySize() const { return EntrySize; }
   
   /// getAlignment - returns the target's preferred alignment for jump tables
-  unsigned getAlignment() const;
+  unsigned getAlignment() const { return Alignment; }
   
   /// print - Used by the MachineFunction printer to print information about
   /// jump tables.  Implemented in MachineFunction.cpp
   ///
   void print(std::ostream &OS) const;
+  void print(std::ostream *OS) const { if (OS) print(*OS); }
 
   /// dump - Call print(std::cerr) to be called from the debugger.
   ///