2006-04-22 20:53:45 +02:00
|
|
|
//===-- CodeGen/MachineJumpTableInfo.h - Abstract Jump Tables --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-04-22 20:53:45 +02: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 14:43:23 +01:00
|
|
|
#include <cassert>
|
2006-04-22 20:53:45 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class MachineBasicBlock;
|
2006-10-16 22:41:42 +02:00
|
|
|
class TargetData;
|
2006-04-22 20:53:45 +02: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 19:44:11 +01:00
|
|
|
explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M)
|
|
|
|
: MBBs(M) {}
|
2006-04-22 20:53:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class MachineJumpTableInfo {
|
2006-12-14 20:17:33 +01:00
|
|
|
unsigned EntrySize;
|
2006-12-14 22:03:17 +01:00
|
|
|
unsigned Alignment;
|
2006-04-22 20:53:45 +02:00
|
|
|
std::vector<MachineJumpTableEntry> JumpTables;
|
|
|
|
public:
|
2006-12-14 22:03:17 +01:00
|
|
|
MachineJumpTableInfo(unsigned Size, unsigned Align)
|
|
|
|
: EntrySize(Size), Alignment(Align) {}
|
2006-04-22 20:53:45 +02:00
|
|
|
|
|
|
|
/// getJumpTableIndex - Create a new jump table or return an existing one.
|
|
|
|
///
|
2006-10-28 20:17:09 +02:00
|
|
|
unsigned getJumpTableIndex(const std::vector<MachineBasicBlock*> &DestBBs);
|
2006-04-22 20:53:45 +02: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 20:12:00 +02: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 22:41:42 +02:00
|
|
|
/// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
|
|
|
|
/// the jump tables to branch to New instead.
|
2006-10-28 20:00:05 +02:00
|
|
|
bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New) {
|
2006-10-28 20:21:51 +02:00
|
|
|
assert(Old != New && "Not making a change?");
|
2006-10-28 20:00:05 +02:00
|
|
|
bool MadeChange = false;
|
2008-05-05 20:30:58 +02:00
|
|
|
for (size_t i = 0, e = JumpTables.size(); i != e; ++i) {
|
2006-10-16 22:41:42 +02:00
|
|
|
MachineJumpTableEntry &JTE = JumpTables[i];
|
2008-05-05 20:30:58 +02:00
|
|
|
for (size_t j = 0, e = JTE.MBBs.size(); j != e; ++j)
|
2006-10-28 20:00:05 +02:00
|
|
|
if (JTE.MBBs[j] == Old) {
|
2006-10-16 22:41:42 +02:00
|
|
|
JTE.MBBs[j] = New;
|
2006-10-28 20:00:05 +02:00
|
|
|
MadeChange = true;
|
|
|
|
}
|
2006-10-16 22:41:42 +02:00
|
|
|
}
|
2006-10-28 20:00:05 +02:00
|
|
|
return MadeChange;
|
2006-10-16 22:41:42 +02:00
|
|
|
}
|
|
|
|
|
2006-12-14 20:17:33 +01:00
|
|
|
/// getEntrySize - Returns the size of an individual field in a jump table.
|
|
|
|
///
|
|
|
|
unsigned getEntrySize() const { return EntrySize; }
|
2006-04-23 01:52:35 +02:00
|
|
|
|
|
|
|
/// getAlignment - returns the target's preferred alignment for jump tables
|
2006-12-14 22:03:17 +01:00
|
|
|
unsigned getAlignment() const { return Alignment; }
|
2006-04-22 20:53:45 +02: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 06:15:13 +01:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
2006-04-22 20:53:45 +02:00
|
|
|
|
|
|
|
/// dump - Call print(std::cerr) to be called from the debugger.
|
|
|
|
///
|
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|