MachineJumpTableInfo.h revision 198090
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 { 43193323Sed unsigned EntrySize; 44193323Sed unsigned Alignment; 45193323Sed std::vector<MachineJumpTableEntry> JumpTables; 46193323Sedpublic: 47193323Sed MachineJumpTableInfo(unsigned Size, unsigned Align) 48193323Sed : EntrySize(Size), Alignment(Align) {} 49193323Sed 50193323Sed /// getJumpTableIndex - Create a new jump table or return an existing one. 51193323Sed /// 52193323Sed unsigned getJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs); 53193323Sed 54193323Sed /// isEmpty - Return true if there are no jump tables. 55193323Sed /// 56193323Sed bool isEmpty() const { return JumpTables.empty(); } 57193323Sed 58193323Sed const std::vector<MachineJumpTableEntry> &getJumpTables() const { 59193323Sed return JumpTables; 60193323Sed } 61193323Sed 62193323Sed /// RemoveJumpTable - Mark the specific index as being dead. This will cause 63193323Sed /// it to not be emitted. 64193323Sed void RemoveJumpTable(unsigned Idx) { 65193323Sed JumpTables[Idx].MBBs.clear(); 66193323Sed } 67193323Sed 68193323Sed /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update 69193323Sed /// the jump tables to branch to New instead. 70193323Sed bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New); 71193323Sed 72193323Sed /// getEntrySize - Returns the size of an individual field in a jump table. 73193323Sed /// 74193323Sed unsigned getEntrySize() const { return EntrySize; } 75193323Sed 76193323Sed /// getAlignment - returns the target's preferred alignment for jump tables 77193323Sed unsigned getAlignment() const { return Alignment; } 78193323Sed 79193323Sed /// print - Used by the MachineFunction printer to print information about 80193323Sed /// jump tables. Implemented in MachineFunction.cpp 81193323Sed /// 82198090Srdivacky void print(raw_ostream &OS) const; 83193323Sed 84198090Srdivacky /// dump - Call to stderr. 85193323Sed /// 86193323Sed void dump() const; 87193323Sed}; 88193323Sed 89193323Sed} // End llvm namespace 90193323Sed 91193323Sed#endif 92