28#define DEBUG_TYPE "aarch64-jump-tables"
30STATISTIC(NumJT8,
"Number of jump-tables with 1-byte entries");
31STATISTIC(NumJT16,
"Number of jump-tables with 2-byte entries");
32STATISTIC(NumJT32,
"Number of jump-tables with 4-byte entries");
60 MachineFunctionProperties::Property::NoVRegs);
63 return "AArch64 Compress Jump Tables";
66char AArch64CompressJumpTables::ID = 0;
70 "AArch64 compress jump tables pass",
false,
false)
79 if (
MI.getOpcode() == AArch64::INLINEASM ||
80 MI.getOpcode() == AArch64::INLINEASM_BR)
87bool AArch64CompressJumpTables::scanFunction() {
96 unsigned OffsetAfterAlignment =
Offset;
98 if (Alignment >
Align(4))
99 OffsetAfterAlignment += Alignment.
value() - 4;
109bool AArch64CompressJumpTables::compressJumpTable(
MachineInstr &
MI,
111 if (
MI.getOpcode() != AArch64::JumpTableDest32)
114 int JTIdx =
MI.getOperand(4).getIndex();
115 auto &JTInfo = *MF->getJumpTableInfo();
122 int MaxOffset = std::numeric_limits<int>::min(),
123 MinOffset = std::numeric_limits<int>::max();
126 int BlockOffset = BlockInfo[
Block->getNumber()];
127 assert(BlockOffset % 4 == 0 &&
"misaligned basic block");
129 MaxOffset = std::max(MaxOffset, BlockOffset);
130 if (BlockOffset <= MinOffset) {
131 MinOffset = BlockOffset;
135 assert(MinBlock &&
"Failed to find minimum offset block");
139 if (!isInt<21>(MinOffset -
Offset)) {
144 int Span = MaxOffset - MinOffset;
146 if (isUInt<8>(Span / 4)) {
148 MI.setDesc(
TII->get(AArch64::JumpTableDest8));
152 if (isUInt<16>(Span / 4)) {
153 AFI->setJumpTableEntryInfo(JTIdx, 2, MinBlock->
getSymbol());
154 MI.setDesc(
TII->get(AArch64::JumpTableDest16));
163bool AArch64CompressJumpTables::runOnMachineFunction(
MachineFunction &MFIn) {
164 bool Changed =
false;
168 TII =
ST.getInstrInfo();
170 if (
ST.force32BitJumpTables() && !MF->getFunction().hasMinSize())
179 Changed |= compressJumpTable(
MI,
Offset);
188 return new AArch64CompressJumpTables();
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static const int BlockSize
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym)
FunctionPass class - This class is used to implement most global optimizations.
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
Align getAlignment() const
Return alignment of the basic block.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
virtual MachineFunctionProperties getRequiredProperties() const
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
Representation of each machine instruction.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createAArch64CompressJumpTablesPass()
void initializeAArch64CompressJumpTablesPass(PassRegistry &)
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
MachineJumpTableEntry - One jump table in the jump table info.