MachineJumpTableInfo.h revision 199481
1//===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump Tables --*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// The MachineJumpTableInfo class keeps track of jump tables referenced by 11// lowered switch instructions in the MachineFunction. 12// 13// Instructions reference the address of these jump tables through the use of 14// MO_JumpTableIndex values. When emitting assembly or machine code, these 15// virtual address references are converted to refer to the address of the 16// function jump tables. 17// 18//===----------------------------------------------------------------------===// 19 20#ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H 21#define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H 22 23#include <vector> 24#include <cassert> 25 26namespace llvm { 27 28class MachineBasicBlock; 29class TargetData; 30class raw_ostream; 31 32/// MachineJumpTableEntry - One jump table in the jump table info. 33/// 34struct MachineJumpTableEntry { 35 /// MBBs - The vector of basic blocks from which to create the jump table. 36 std::vector<MachineBasicBlock*> MBBs; 37 38 explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M) 39 : MBBs(M) {} 40}; 41 42class MachineJumpTableInfo { 43 unsigned EntrySize; 44 unsigned Alignment; 45 std::vector<MachineJumpTableEntry> JumpTables; 46public: 47 MachineJumpTableInfo(unsigned Size, unsigned Align) 48 : EntrySize(Size), Alignment(Align) {} 49 50 /// getJumpTableIndex - Create a new jump table or return an existing one. 51 /// 52 unsigned getJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs); 53 54 /// isEmpty - Return true if there are no jump tables. 55 /// 56 bool isEmpty() const { return JumpTables.empty(); } 57 58 const std::vector<MachineJumpTableEntry> &getJumpTables() const { 59 return JumpTables; 60 } 61 62 /// RemoveJumpTable - Mark the specific index as being dead. This will cause 63 /// it to not be emitted. 64 void RemoveJumpTable(unsigned Idx) { 65 JumpTables[Idx].MBBs.clear(); 66 } 67 68 /// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update 69 /// the jump tables to branch to New instead. 70 bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New); 71 72 /// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update 73 /// the jump table to branch to New instead. 74 bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old, 75 MachineBasicBlock *New); 76 77 /// getEntrySize - Returns the size of an individual field in a jump table. 78 /// 79 unsigned getEntrySize() const { return EntrySize; } 80 81 /// getAlignment - returns the target's preferred alignment for jump tables 82 unsigned getAlignment() const { return Alignment; } 83 84 /// print - Used by the MachineFunction printer to print information about 85 /// jump tables. Implemented in MachineFunction.cpp 86 /// 87 void print(raw_ostream &OS) const; 88 89 /// dump - Call to stderr. 90 /// 91 void dump() const; 92}; 93 94} // End llvm namespace 95 96#endif 97