LLVM API Documentation
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 assert(Old != New && "Not making a change?"); 00072 bool MadeChange = false; 00073 for (size_t i = 0, e = JumpTables.size(); i != e; ++i) { 00074 MachineJumpTableEntry &JTE = JumpTables[i]; 00075 for (size_t j = 0, e = JTE.MBBs.size(); j != e; ++j) 00076 if (JTE.MBBs[j] == Old) { 00077 JTE.MBBs[j] = New; 00078 MadeChange = true; 00079 } 00080 } 00081 return MadeChange; 00082 } 00083 00084 /// getEntrySize - Returns the size of an individual field in a jump table. 00085 /// 00086 unsigned getEntrySize() const { return EntrySize; } 00087 00088 /// getAlignment - returns the target's preferred alignment for jump tables 00089 unsigned getAlignment() const { return Alignment; } 00090 00091 /// print - Used by the MachineFunction printer to print information about 00092 /// jump tables. Implemented in MachineFunction.cpp 00093 /// 00094 void print(std::ostream &OS) const; 00095 void print(std::ostream *OS) const { if (OS) print(*OS); } 00096 00097 /// dump - Call print(std::cerr) to be called from the debugger. 00098 /// 00099 void dump() const; 00100 }; 00101 00102 } // End llvm namespace 00103 00104 #endif