MachineJumpTableInfo.h revision 205407
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, 50203954Srdivacky 51203954Srdivacky /// EK_GPRel32BlockAddress - Each entry is an address of block, encoded 52203954Srdivacky /// with a relocation as gp-relative, e.g.: 53203954Srdivacky /// .gprel32 LBB123 54203954Srdivacky EK_GPRel32BlockAddress, 55203954Srdivacky 56203954Srdivacky /// EK_LabelDifference32 - Each entry is the address of the block minus 57203954Srdivacky /// the address of the jump table. This is used for PIC jump tables where 58203954Srdivacky /// gprel32 is not supported. e.g.: 59203954Srdivacky /// .word LBB123 - LJTI1_2 60203954Srdivacky /// If the .set directive is supported, this is emitted as: 61203954Srdivacky /// .set L4_5_set_123, LBB123 - LJTI1_2 62203954Srdivacky /// .word L4_5_set_123 63203954Srdivacky EK_LabelDifference32, 64205218Srdivacky 65205218Srdivacky /// EK_Inline - Jump table entries are emitted inline at their point of 66205218Srdivacky /// use. It is the responsibility of the target to emit the entries. 67205218Srdivacky EK_Inline, 68205218Srdivacky 69203954Srdivacky /// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the 70203954Srdivacky /// TargetLowering::LowerCustomJumpTableEntry hook. 71203954Srdivacky EK_Custom32 72203954Srdivacky }; 73203954Srdivackyprivate: 74203954Srdivacky JTEntryKind EntryKind; 75193323Sed std::vector<MachineJumpTableEntry> JumpTables; 76193323Sedpublic: 77203954Srdivacky MachineJumpTableInfo(JTEntryKind Kind): EntryKind(Kind) {} 78193323Sed 79203954Srdivacky JTEntryKind getEntryKind() const { return EntryKind; } 80203954Srdivacky 81203954Srdivacky /// getEntrySize - Return the size of each entry in the jump table. 82203954Srdivacky unsigned getEntrySize(const TargetData &TD) const; 83203954Srdivacky /// getEntryAlignment - Return the alignment of each entry in the jump table. 84203954Srdivacky unsigned getEntryAlignment(const TargetData &TD) const; 85203954Srdivacky 86205407Srdivacky /// createJumpTableIndex - Create a new jump table. 87193323Sed /// 88205407Srdivacky unsigned createJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs); 89193323Sed 90193323Sed /// isEmpty - Return true if there are no jump tables. 91193323Sed /// 92193323Sed bool isEmpty() const { return JumpTables.empty(); } 93193323Sed 94193323Sed const std::vector<MachineJumpTableEntry> &getJumpTables() const { 95193323Sed return JumpTables; 96193323Sed } 97203954Srdivacky 98203954Srdivacky /// RemoveJumpTable - Mark the specific index as being dead. This will 99203954Srdivacky /// prevent it from being emitted. 100193323Sed void RemoveJumpTable(unsigned Idx) { 101193323Sed JumpTables[Idx].MBBs.clear(); 102193323Sed } 103193323Sed 104193323Sed /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update 105193323Sed /// the jump tables to branch to New instead. 106193323Sed bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New); 107193323Sed 108199481Srdivacky /// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update 109199481Srdivacky /// the jump table to branch to New instead. 110199481Srdivacky bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old, 111199481Srdivacky MachineBasicBlock *New); 112199481Srdivacky 113193323Sed /// print - Used by the MachineFunction printer to print information about 114193323Sed /// jump tables. Implemented in MachineFunction.cpp 115193323Sed /// 116198090Srdivacky void print(raw_ostream &OS) const; 117193323Sed 118198090Srdivacky /// dump - Call to stderr. 119193323Sed /// 120193323Sed void dump() const; 121193323Sed}; 122193323Sed 123193323Sed} // End llvm namespace 124193323Sed 125193323Sed#endif 126