28 #define DEBUG_TYPE "aarch64-jump-tables" 30 STATISTIC(NumJT8,
"Number of jump-tables with 1-byte entries");
31 STATISTIC(NumJT16,
"Number of jump-tables with 2-byte entries");
32 STATISTIC(NumJT32,
"Number of jump-tables with 4-byte entries");
58 return "AArch64 Compress Jump Tables";
65 "AArch64 compress jump tables pass",
false,
false)
74 void AArch64CompressJumpTables::scanFunction() {
80 const Align Alignment = MBB.getAlignment();
81 unsigned AlignedOffset;
85 AlignedOffset =
alignTo(Offset, Alignment);
86 BlockInfo[MBB.getNumber()] = AlignedOffset;
87 Offset = AlignedOffset + computeBlockSize(MBB);
91 bool AArch64CompressJumpTables::compressJumpTable(
MachineInstr &
MI,
93 if (MI.
getOpcode() != AArch64::JumpTableDest32)
104 int MaxOffset = std::numeric_limits<int>::min(),
107 for (
auto Block : JT.
MBBs) {
108 int BlockOffset = BlockInfo[Block->getNumber()];
109 assert(BlockOffset % 4 == 0 &&
"misaligned basic block");
111 MaxOffset =
std::max(MaxOffset, BlockOffset);
112 if (BlockOffset <= MinOffset) {
113 MinOffset = BlockOffset;
117 assert(MinBlock &&
"Failed to find minimum offset block");
121 if (!isInt<21>(MinOffset - Offset)) {
126 int Span = MaxOffset - MinOffset;
130 MI.
setDesc(TII->
get(AArch64::JumpTableDest8));
134 AFI->setJumpTableEntryInfo(JTIdx, 2, MinBlock->
getSymbol());
135 MI.
setDesc(TII->
get(AArch64::JumpTableDest16));
144 bool AArch64CompressJumpTables::runOnMachineFunction(
MachineFunction &MFIn) {
145 bool Changed =
false;
149 TII =
ST.getInstrInfo();
157 int Offset = BlockInfo[MBB.getNumber()];
159 Changed |= compressJumpTable(MI, Offset);
160 Offset += TII->getInstSizeInBytes(MI);
168 return new AArch64CompressJumpTables();
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
This class represents lattice values for constants.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
STATISTIC(NumFunctions, "Total number of functions")
virtual unsigned getInstSizeInBytes(const MachineInstr &MI) const
Returns the size in bytes of the specified MachineInstr, or ~0U when this function is not implemented...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
TargetInstrInfo - Interface to description of machine instruction set.
constexpr bool isUInt< 8 >(uint64_t x)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym)
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
std::vector< MachineBasicBlock * > MBBs
MBBs - The vector of basic blocks from which to create the jump table.
static constexpr const Align None()
Returns a default constructed Align which corresponds to no alignment.
This struct is a compact representation of a valid (non-zero power of two) alignment.
INITIALIZE_PASS(AArch64CompressJumpTables, DEBUG_TYPE, "AArch64 compress jump tables pass", false, false) int AArch64CompressJumpTables
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
Align max(MaybeAlign Lhs, Align Rhs)
const Function & getFunction() const
Return the LLVM function that this machine code represents.
MachineJumpTableEntry - One jump table in the jump table info.
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
constexpr bool isUInt< 16 >(uint64_t x)
void initializeAArch64CompressJumpTablesPass(PassRegistry &)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
const MachineOperand & getOperand(unsigned i) const
Properties which a MachineFunction may have at a given point in time.
FunctionPass * createAArch64CompressJumpTablesPass()