MachineJumpTableInfo.h revision 234353
1193323Sed//===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump Tables --*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// The MachineJumpTableInfo class keeps track of jump tables referenced by 11193323Sed// lowered switch instructions in the MachineFunction. 12193323Sed// 13193323Sed// Instructions reference the address of these jump tables through the use of 14193323Sed// MO_JumpTableIndex values. When emitting assembly or machine code, these 15193323Sed// virtual address references are converted to refer to the address of the 16193323Sed// function jump tables. 17193323Sed// 18193323Sed//===----------------------------------------------------------------------===// 19193323Sed 20193323Sed#ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H 21193323Sed#define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H 22193323Sed 23193323Sed#include <vector> 24193323Sed#include <cassert> 25193323Sed 26193323Sednamespace llvm { 27193323Sed 28193323Sedclass MachineBasicBlock; 29193323Sedclass TargetData; 30198090Srdivackyclass raw_ostream; 31193323Sed 32193323Sed/// MachineJumpTableEntry - One jump table in the jump table info. 33193323Sed/// 34193323Sedstruct MachineJumpTableEntry { 35193323Sed /// MBBs - The vector of basic blocks from which to create the jump table. 36193323Sed std::vector<MachineBasicBlock*> MBBs; 37193323Sed 38193323Sed explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M) 39193323Sed : MBBs(M) {} 40193323Sed}; 41193323Sed 42193323Sedclass MachineJumpTableInfo { 43203954Srdivackypublic: 44203954Srdivacky /// JTEntryKind - This enum indicates how each entry of the jump table is 45203954Srdivacky /// represented and emitted. 46203954Srdivacky enum JTEntryKind { 47203954Srdivacky /// EK_BlockAddress - Each entry is a plain address of block, e.g.: 48203954Srdivacky /// .word LBB123 49203954Srdivacky EK_BlockAddress, 50234353Sdim 51234353Sdim /// EK_GPRel64BlockAddress - Each entry is an address of block, encoded 52234353Sdim /// with a relocation as gp-relative, e.g.: 53234353Sdim /// .gpdword LBB123 54234353Sdim EK_GPRel64BlockAddress, 55234353Sdim 56203954Srdivacky /// EK_GPRel32BlockAddress - Each entry is an address of block, encoded 57203954Srdivacky /// with a relocation as gp-relative, e.g.: 58203954Srdivacky /// .gprel32 LBB123 59203954Srdivacky EK_GPRel32BlockAddress, 60203954Srdivacky 61203954Srdivacky /// EK_LabelDifference32 - Each entry is the address of the block minus 62203954Srdivacky /// the address of the jump table. This is used for PIC jump tables where 63203954Srdivacky /// gprel32 is not supported. e.g.: 64203954Srdivacky /// .word LBB123 - LJTI1_2 65203954Srdivacky /// If the .set directive is supported, this is emitted as: 66203954Srdivacky /// .set L4_5_set_123, LBB123 - LJTI1_2 67203954Srdivacky /// .word L4_5_set_123 68203954Srdivacky EK_LabelDifference32, 69205218Srdivacky 70205218Srdivacky /// EK_Inline - Jump table entries are emitted inline at their point of 71205218Srdivacky /// use. It is the responsibility of the target to emit the entries. 72205218Srdivacky EK_Inline, 73205218Srdivacky 74203954Srdivacky /// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the 75203954Srdivacky /// TargetLowering::LowerCustomJumpTableEntry hook. 76203954Srdivacky EK_Custom32 77203954Srdivacky }; 78203954Srdivackyprivate: 79203954Srdivacky JTEntryKind EntryKind; 80193323Sed std::vector<MachineJumpTableEntry> JumpTables; 81193323Sedpublic: 82210299Sed explicit MachineJumpTableInfo(JTEntryKind Kind): EntryKind(Kind) {} 83193323Sed 84203954Srdivacky JTEntryKind getEntryKind() const { return EntryKind; } 85203954Srdivacky 86203954Srdivacky /// getEntrySize - Return the size of each entry in the jump table. 87203954Srdivacky unsigned getEntrySize(const TargetData &TD) const; 88203954Srdivacky /// getEntryAlignment - Return the alignment of each entry in the jump table. 89203954Srdivacky unsigned getEntryAlignment(const TargetData &TD) const; 90203954Srdivacky 91205407Srdivacky /// createJumpTableIndex - Create a new jump table. 92193323Sed /// 93205407Srdivacky unsigned createJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs); 94193323Sed 95193323Sed /// isEmpty - Return true if there are no jump tables. 96193323Sed /// 97193323Sed bool isEmpty() const { return JumpTables.empty(); } 98193323Sed 99193323Sed const std::vector<MachineJumpTableEntry> &getJumpTables() const { 100193323Sed return JumpTables; 101193323Sed } 102203954Srdivacky 103203954Srdivacky /// RemoveJumpTable - Mark the specific index as being dead. This will 104203954Srdivacky /// prevent it from being emitted. 105193323Sed void RemoveJumpTable(unsigned Idx) { 106193323Sed JumpTables[Idx].MBBs.clear(); 107193323Sed } 108193323Sed 109193323Sed /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update 110193323Sed /// the jump tables to branch to New instead. 111193323Sed bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New); 112193323Sed 113199481Srdivacky /// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update 114199481Srdivacky /// the jump table to branch to New instead. 115199481Srdivacky bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old, 116199481Srdivacky MachineBasicBlock *New); 117199481Srdivacky 118193323Sed /// print - Used by the MachineFunction printer to print information about 119193323Sed /// jump tables. Implemented in MachineFunction.cpp 120193323Sed /// 121198090Srdivacky void print(raw_ostream &OS) const; 122193323Sed 123198090Srdivacky /// dump - Call to stderr. 124193323Sed /// 125193323Sed void dump() const; 126193323Sed}; 127193323Sed 128193323Sed} // End llvm namespace 129193323Sed 130193323Sed#endif 131