26#define DEBUG_TYPE "aarch64-jump-tables"
28STATISTIC(NumJT8,
"Number of jump-tables with 1-byte entries");
29STATISTIC(NumJT16,
"Number of jump-tables with 2-byte entries");
30STATISTIC(NumJT32,
"Number of jump-tables with 4-byte entries");
33class AArch64CompressJumpTablesImpl {
55 AArch64CompressJumpTablesLegacy() : MachineFunctionPass(ID) {}
57 bool runOnMachineFunction(MachineFunction &MF)
override;
59 MachineFunctionProperties getRequiredProperties()
const override {
60 return MachineFunctionProperties().setNoVRegs();
62 StringRef getPassName()
const override {
63 return "AArch64 Compress Jump Tables";
66char AArch64CompressJumpTablesLegacy::ID = 0;
70 "AArch64 compress jump tables pass",
false,
false)
79 if (
MI.getOpcode() == AArch64::INLINEASM ||
80 MI.getOpcode() == AArch64::INLINEASM_BR)
87bool AArch64CompressJumpTablesImpl::scanFunction() {
94 for (MachineBasicBlock &
MBB : *MF) {
96 unsigned OffsetAfterAlignment =
Offset;
98 if (Alignment >
Align(4))
99 OffsetAfterAlignment += Alignment.
value() - 4;
109bool AArch64CompressJumpTablesImpl::compressJumpTable(MachineInstr &
MI,
111 if (
MI.getOpcode() != AArch64::JumpTableDest32)
114 int JTIdx =
MI.getOperand(4).getIndex();
115 auto &JTInfo = *MF->getJumpTableInfo();
116 const MachineJumpTableEntry &JT = JTInfo.getJumpTables()[JTIdx];
122 int MaxOffset = std::numeric_limits<int>::min(),
123 MinOffset = std::numeric_limits<int>::max();
124 MachineBasicBlock *MinBlock =
nullptr;
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");
144 int Span = MaxOffset - MinOffset;
145 auto *AFI = MF->getInfo<AArch64FunctionInfo>();
147 AFI->setJumpTableEntryInfo(JTIdx, 1, MinBlock->
getSymbol());
148 MI.setDesc(
TII->get(AArch64::JumpTableDest8));
153 AFI->setJumpTableEntryInfo(JTIdx, 2, MinBlock->
getSymbol());
154 MI.setDesc(
TII->get(AArch64::JumpTableDest16));
163bool AArch64CompressJumpTablesImpl::run(MachineFunction &MFIn) {
167 const auto &
ST = MF->getSubtarget<AArch64Subtarget>();
168 TII =
ST.getInstrInfo();
170 if (
ST.force32BitJumpTables() && !MF->getFunction().hasMinSize())
176 for (MachineBasicBlock &
MBB : *MF) {
178 for (MachineInstr &
MI :
MBB) {
187bool AArch64CompressJumpTablesLegacy::runOnMachineFunction(
188 MachineFunction &MF) {
189 return AArch64CompressJumpTablesImpl().run(MF);
195 const bool Changed = AArch64CompressJumpTablesImpl().run(MF);
204 return new AArch64CompressJumpTablesLegacy();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const HexagonInstrInfo * TII
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
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
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
LLVM_ABI 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...
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
Representation of each machine instruction.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
This is an optimization pass for GlobalISel generic memory operations.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
FunctionPass * createAArch64CompressJumpTablesPass()
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Implement std::hash so that hash_code can be used in STL containers.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
std::vector< MachineBasicBlock * > MBBs
MBBs - The vector of basic blocks from which to create the jump table.