2006-04-22 18:53:45 +00:00
|
|
|
//===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump Tables --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-04-22 18:53:45 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The MachineJumpTableInfo class keeps track of jump tables referenced by
|
|
|
|
// lowered switch instructions in the MachineFunction.
|
|
|
|
//
|
|
|
|
// Instructions reference the address of these jump tables through the use of
|
|
|
|
// MO_JumpTableIndex values. When emitting assembly or machine code, these
|
|
|
|
// virtual address references are converted to refer to the address of the
|
|
|
|
// function jump tables.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEJUMPTABLEINFO_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <iosfwd>
|
2007-11-12 13:43:23 +00:00
|
|
|
#include <cassert>
|
2006-04-22 18:53:45 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class MachineBasicBlock;
|
2006-10-16 20:41:42 +00:00
|
|
|
class TargetData;
|
2006-04-22 18:53:45 +00:00
|
|
|
|
|
|
|
/// MachineJumpTableEntry - One jump table in the jump table info.
|
|
|
|
///
|
|
|
|
struct MachineJumpTableEntry {
|
|
|
|
/// MBBs - The vector of basic blocks from which to create the jump table.
|
|
|
|
std::vector<MachineBasicBlock*> MBBs;
|
|
|
|
|
2007-03-23 18:44:11 +00:00
|
|
|
explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M)
|
|
|
|
: MBBs(M) {}
|
2006-04-22 18:53:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MachineJumpTableInfo {
|
2006-12-14 19:17:33 +00:00
|
|
|
unsigned EntrySize;
|
2006-12-14 21:03:17 +00:00
|
|
|
unsigned Alignment;
|
2006-04-22 18:53:45 +00:00
|
|
|
std::vector<MachineJumpTableEntry> JumpTables;
|
|
|
|
public:
|
2006-12-14 21:03:17 +00:00
|
|
|
MachineJumpTableInfo(unsigned Size, unsigned Align)
|
|
|
|
: EntrySize(Size), Alignment(Align) {}
|
2006-04-22 18:53:45 +00:00
|
|
|
|
|
|
|
/// getJumpTableIndex - Create a new jump table or return an existing one.
|
|
|
|
///
|
2006-10-28 18:17:09 +00:00
|
|
|
unsigned getJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
|
2006-04-22 18:53:45 +00:00
|
|
|
|
|
|
|
/// isEmpty - Return true if there are no jump tables.
|
|
|
|
///
|
|
|
|
bool isEmpty() const { return JumpTables.empty(); }
|
|
|
|
|
|
|
|
const std::vector<MachineJumpTableEntry> &getJumpTables() const {
|
|
|
|
return JumpTables;
|
|
|
|
}
|
|
|
|
|
2006-10-28 18:12:00 +00:00
|
|
|
/// RemoveJumpTable - Mark the specific index as being dead. This will cause
|
|
|
|
/// it to not be emitted.
|
|
|
|
void RemoveJumpTable(unsigned Idx) {
|
|
|
|
JumpTables[Idx].MBBs.clear();
|
|
|
|
}
|
|
|
|
|
2006-10-16 20:41:42 +00:00
|
|
|
/// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
|
|
|
|
/// the jump tables to branch to New instead.
|
2009-04-15 01:18:49 +00:00
|
|
|
bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New);
|
|
|
|
|
2006-12-14 19:17:33 +00:00
|
|
|
/// getEntrySize - Returns the size of an individual field in a jump table.
|
|
|
|
///
|
|
|
|
unsigned getEntrySize() const { return EntrySize; }
|
2006-04-22 23:52:35 +00:00
|
|
|
|
|
|
|
/// getAlignment - returns the target's preferred alignment for jump tables
|
2006-12-14 21:03:17 +00:00
|
|
|
unsigned getAlignment() const { return Alignment; }
|
2006-04-22 18:53:45 +00:00
|
|
|
|
|
|
|
/// print - Used by the MachineFunction printer to print information about
|
|
|
|
/// jump tables. Implemented in MachineFunction.cpp
|
|
|
|
///
|
|
|
|
void print(std::ostream &OS) const;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
2006-04-22 18:53:45 +00:00
|
|
|
|
|
|
|
/// dump - Call print(std::cerr) to be called from the debugger.
|
|
|
|
///
|
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|