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>
|
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;
|
2009-08-23 01:12:47 +00:00
|
|
|
class raw_ostream;
|
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 {
|
2010-01-25 23:26:13 +00:00
|
|
|
public:
|
|
|
|
/// JTEntryKind - This enum indicates how each entry of the jump table is
|
|
|
|
/// represented and emitted.
|
|
|
|
enum JTEntryKind {
|
|
|
|
/// EK_BlockAddress - Each entry is a plain address of block, e.g.:
|
|
|
|
/// .word LBB123
|
|
|
|
EK_BlockAddress,
|
|
|
|
|
|
|
|
/// EK_GPRel32BlockAddress - Each entry is an address of block, encoded
|
|
|
|
/// with a relocation as gp-relative, e.g.:
|
|
|
|
/// .gprel32 LBB123
|
|
|
|
EK_GPRel32BlockAddress,
|
|
|
|
|
|
|
|
/// EK_LabelDifference32 - Each entry is the address of the block minus
|
|
|
|
/// the address of the jump table. This is used for PIC jump tables where
|
|
|
|
/// gprel32 is not supported. e.g.:
|
|
|
|
/// .word LBB123 - LJTI1_2
|
|
|
|
/// If the .set directive is supported, this is emitted as:
|
|
|
|
/// .set L4_5_set_123, LBB123 - LJTI1_2
|
|
|
|
/// .word L4_5_set_123
|
2010-01-26 04:05:28 +00:00
|
|
|
EK_LabelDifference32,
|
2010-03-11 14:58:16 +00:00
|
|
|
|
|
|
|
/// EK_Inline - Jump table entries are emitted inline at their point of
|
|
|
|
/// use. It is the responsibility of the target to emit the entries.
|
|
|
|
EK_Inline,
|
|
|
|
|
2010-01-26 04:05:28 +00:00
|
|
|
/// EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the
|
|
|
|
/// TargetLowering::LowerCustomJumpTableEntry hook.
|
|
|
|
EK_Custom32
|
2010-01-25 23:26:13 +00:00
|
|
|
};
|
|
|
|
private:
|
|
|
|
JTEntryKind EntryKind;
|
2006-04-22 18:53:45 +00:00
|
|
|
std::vector<MachineJumpTableEntry> JumpTables;
|
|
|
|
public:
|
2010-01-25 23:26:13 +00:00
|
|
|
MachineJumpTableInfo(JTEntryKind Kind): EntryKind(Kind) {}
|
2006-04-22 18:53:45 +00:00
|
|
|
|
2010-01-25 23:26:13 +00:00
|
|
|
JTEntryKind getEntryKind() const { return EntryKind; }
|
|
|
|
|
|
|
|
/// getEntrySize - Return the size of each entry in the jump table.
|
|
|
|
unsigned getEntrySize(const TargetData &TD) const;
|
|
|
|
/// getEntryAlignment - Return the alignment of each entry in the jump table.
|
|
|
|
unsigned getEntryAlignment(const TargetData &TD) const;
|
|
|
|
|
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;
|
|
|
|
}
|
2010-01-26 05:58:28 +00:00
|
|
|
|
2010-01-25 23:26:13 +00:00
|
|
|
/// RemoveJumpTable - Mark the specific index as being dead. This will
|
|
|
|
/// prevent it from being emitted.
|
2006-10-28 18:12:00 +00:00
|
|
|
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);
|
|
|
|
|
2009-11-14 20:09:13 +00:00
|
|
|
/// ReplaceMBBInJumpTable - If Old is a target of the jump tables, update
|
|
|
|
/// the jump table to branch to New instead.
|
|
|
|
bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old,
|
|
|
|
MachineBasicBlock *New);
|
|
|
|
|
2006-04-22 18:53:45 +00:00
|
|
|
/// print - Used by the MachineFunction printer to print information about
|
|
|
|
/// jump tables. Implemented in MachineFunction.cpp
|
|
|
|
///
|
2009-08-23 01:12:47 +00:00
|
|
|
void print(raw_ostream &OS) const;
|
2006-04-22 18:53:45 +00:00
|
|
|
|
2009-08-03 01:02:24 +00:00
|
|
|
/// dump - Call to stderr.
|
2006-04-22 18:53:45 +00:00
|
|
|
///
|
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|