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 <cassert> 00024 #include <vector> 00025 00026 namespace llvm { 00027 00028 class MachineBasicBlock; 00029 class DataLayout; 00030 class raw_ostream; 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 public: 00044 /// JTEntryKind - This enum indicates how each entry of the jump table is 00045 /// represented and emitted. 00046 enum JTEntryKind { 00047 /// EK_BlockAddress - Each entry is a plain address of block, e.g.: 00048 /// .word LBB123 00049 EK_BlockAddress, 00050 00051 /// EK_GPRel64BlockAddress - Each entry is an address of block, encoded 00052 /// with a relocation as gp-relative, e.g.: 00053 /// .gpdword LBB123 00054 EK_GPRel64BlockAddress, 00055 00056 /// EK_GPRel32BlockAddress - Each entry is an address of block, encoded 00057 /// with a relocation as gp-relative, e.g.: 00058 /// .gprel32 LBB123 00059 EK_GPRel32BlockAddress, 00060 00061 /// EK_LabelDifference32 - Each entry is the address of the block minus 00062 /// the address of the jump table. This is used for PIC jump tables where 00063 /// gprel32 is not supported. e.g.: 00064 /// .word LBB123 - LJTI1_2 00065 /// If the .set directive is supported, this is emitted as: 00066 /// .set L4_5_set_123, LBB123 - LJTI1_2 00067 /// .word L4_5_set_123 00068 EK_LabelDifference32, 00069 00070 /// EK_Inline - Jump table entries are emitted inline at their point of 00071 /// use. It is the responsibility of the target to emit the entries. 00072 EK_Inline, 00073 00074 /// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the 00075 /// TargetLowering::LowerCustomJumpTableEntry hook. 00076 EK_Custom32 00077 }; 00078 private: 00079 JTEntryKind EntryKind; 00080 std::vector<MachineJumpTableEntry> JumpTables; 00081 public: 00082 explicit MachineJumpTableInfo(JTEntryKind Kind): EntryKind(Kind) {} 00083 00084 JTEntryKind getEntryKind() const { return EntryKind; } 00085 00086 /// getEntrySize - Return the size of each entry in the jump table. 00087 unsigned getEntrySize(const DataLayout &TD) const; 00088 /// getEntryAlignment - Return the alignment of each entry in the jump table. 00089 unsigned getEntryAlignment(const DataLayout &TD) const; 00090 00091 /// createJumpTableIndex - Create a new jump table. 00092 /// 00093 unsigned createJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs); 00094 00095 /// isEmpty - Return true if there are no jump tables. 00096 /// 00097 bool isEmpty() const { return JumpTables.empty(); } 00098 00099 const std::vector<MachineJumpTableEntry> &getJumpTables() const { 00100 return JumpTables; 00101 } 00102 00103 /// RemoveJumpTable - Mark the specific index as being dead. This will 00104 /// prevent it from being emitted. 00105 void RemoveJumpTable(unsigned Idx) { 00106 JumpTables[Idx].MBBs.clear(); 00107 } 00108 00109 /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update 00110 /// the jump tables to branch to New instead. 00111 bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New); 00112 00113 /// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update 00114 /// the jump table to branch to New instead. 00115 bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old, 00116 MachineBasicBlock *New); 00117 00118 /// print - Used by the MachineFunction printer to print information about 00119 /// jump tables. Implemented in MachineFunction.cpp 00120 /// 00121 void print(raw_ostream &OS) const; 00122 00123 /// dump - Call to stderr. 00124 /// 00125 void dump() const; 00126 }; 00127 00128 } // End llvm namespace 00129 00130 #endif