2006-04-22 18:53:45 +00:00
|
|
|
//===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump Tables --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Nate Begeman and is distributed under the
|
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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>
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
MachineJumpTableEntry(std::vector<MachineBasicBlock*> &M) : MBBs(M) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MachineJumpTableInfo {
|
2006-05-03 01:29:57 +00:00
|
|
|
const TargetData *TD;
|
2006-04-22 18:53:45 +00:00
|
|
|
std::vector<MachineJumpTableEntry> JumpTables;
|
|
|
|
public:
|
2006-05-03 01:29:57 +00:00
|
|
|
MachineJumpTableInfo(const TargetData *td) : TD(td) {}
|
2006-04-22 18:53:45 +00:00
|
|
|
|
|
|
|
/// getJumpTableIndex - Create a new jump table or return an existing one.
|
|
|
|
///
|
|
|
|
unsigned getJumpTableIndex(std::vector<MachineBasicBlock*> &DestBBs);
|
|
|
|
|
|
|
|
/// 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-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.
|
2006-10-28 18:00:05 +00:00
|
|
|
bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New) {
|
|
|
|
bool MadeChange = false;
|
2006-10-16 20:41:42 +00:00
|
|
|
for (unsigned i = 0, e = JumpTables.size(); i != e; ++i) {
|
|
|
|
MachineJumpTableEntry &JTE = JumpTables[i];
|
|
|
|
for (unsigned j = 0, e = JTE.MBBs.size(); j != e; ++j)
|
2006-10-28 18:00:05 +00:00
|
|
|
if (JTE.MBBs[j] == Old) {
|
2006-10-16 20:41:42 +00:00
|
|
|
JTE.MBBs[j] = New;
|
2006-10-28 18:00:05 +00:00
|
|
|
MadeChange = true;
|
|
|
|
}
|
2006-10-16 20:41:42 +00:00
|
|
|
}
|
2006-10-28 18:00:05 +00:00
|
|
|
return MadeChange;
|
2006-10-16 20:41:42 +00:00
|
|
|
}
|
|
|
|
|
2006-04-22 23:52:35 +00:00
|
|
|
/// getEntrySize - returns the size of an individual field in a jump table
|
|
|
|
unsigned getEntrySize() const;
|
|
|
|
|
|
|
|
/// getAlignment - returns the target's preferred alignment for jump tables
|
|
|
|
unsigned getAlignment() const;
|
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;
|
|
|
|
|
|
|
|
/// dump - Call print(std::cerr) to be called from the debugger.
|
|
|
|
///
|
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|