LLVM API Documentation

MachineJumpTableInfo.h

Go to the documentation of this file.
00001 //===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump Tables  --*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // The MachineJumpTableInfo class keeps track of jump tables referenced by
00011 // lowered switch instructions in the MachineFunction.
00012 //
00013 // Instructions reference the address of these jump tables through the use of 
00014 // MO_JumpTableIndex values.  When emitting assembly or machine code, these 
00015 // virtual address references are converted to refer to the address of the 
00016 // function jump tables.
00017 //
00018 //===----------------------------------------------------------------------===//
00019 
00020 #ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
00021 #define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
00022 
00023 #include <vector>
00024 #include <iosfwd>
00025 #include <cassert>
00026 
00027 namespace llvm {
00028 
00029 class MachineBasicBlock;
00030 class TargetData;
00031 
00032 /// MachineJumpTableEntry - One jump table in the jump table info.
00033 ///
00034 struct MachineJumpTableEntry {
00035   /// MBBs - The vector of basic blocks from which to create the jump table.
00036   std::vector<MachineBasicBlock*> MBBs;
00037   
00038   explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M)
00039   : MBBs(M) {}
00040 };
00041   
00042 class MachineJumpTableInfo {
00043   unsigned EntrySize;
00044   unsigned Alignment;
00045   std::vector<MachineJumpTableEntry> JumpTables;
00046 public:
00047   MachineJumpTableInfo(unsigned Size, unsigned Align)
00048   : EntrySize(Size), Alignment(Align) {}
00049     
00050   /// getJumpTableIndex - Create a new jump table or return an existing one.
00051   ///
00052   unsigned getJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
00053   
00054   /// isEmpty - Return true if there are no jump tables.
00055   ///
00056   bool isEmpty() const { return JumpTables.empty(); }
00057 
00058   const std::vector<MachineJumpTableEntry> &getJumpTables() const {
00059     return JumpTables;
00060   }
00061   
00062   /// RemoveJumpTable - Mark the specific index as being dead.  This will cause
00063   /// it to not be emitted.
00064   void RemoveJumpTable(unsigned Idx) {
00065     JumpTables[Idx].MBBs.clear();
00066   }
00067   
00068   /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
00069   /// the jump tables to branch to New instead.
00070   bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New);
00071 
00072   /// getEntrySize - Returns the size of an individual field in a jump table. 
00073   ///
00074   unsigned getEntrySize() const { return EntrySize; }
00075   
00076   /// getAlignment - returns the target's preferred alignment for jump tables
00077   unsigned getAlignment() const { return Alignment; }
00078   
00079   /// print - Used by the MachineFunction printer to print information about
00080   /// jump tables.  Implemented in MachineFunction.cpp
00081   ///
00082   void print(std::ostream &OS) const;
00083   void print(std::ostream *OS) const { if (OS) print(*OS); }
00084 
00085   /// dump - Call to stderr.
00086   ///
00087   void dump() const;
00088 };
00089 
00090 } // End llvm namespace
00091 
00092 #endif