Skip to content

Commit 5d207e9

Browse files
[SDP]Introduce StaticDataSplitter pass and implemenet jump table splitting
1 parent cd66c9b commit 5d207e9

13 files changed

+363
-2
lines changed

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,12 @@ class MachineBasicBlock
997997
/// no changes occurred in the meantime.
998998
bool canSplitCriticalEdge(const MachineBasicBlock *Succ) const;
999999

1000+
/// Return an index for MachineJumpTableInfo if \p this basic block ends with
1001+
/// an indirect jump using a jump table, otherwise -1.
1002+
/// This function is a thin wrapper and forward calls to the per-target method
1003+
/// `TargetInstrInfo::getjumpTableIndex`.
1004+
int getJumpTableIndex() const;
1005+
10001006
void pop_front() { Insts.pop_front(); }
10011007
void pop_back() { Insts.pop_back(); }
10021008
void push_back(MachineInstr *MI) { Insts.push_back(MI); }

llvm/include/llvm/CodeGen/MachineFunction.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ template <> struct ilist_callback_traits<MachineBasicBlock> {
8888
}
8989
};
9090

91+
// The hotness of static data tracked by a MachineFunction and not represented
92+
// as a global object in the module IR / MIR. Typical examples are
93+
// MachineJumpTableInfo and MachineConstantPool.
94+
enum class DataHotness {
95+
Unknown,
96+
Cold,
97+
Hot,
98+
};
99+
91100
/// MachineFunctionInfo - This class can be derived from and used by targets to
92101
/// hold private target-specific information for each MachineFunction. Objects
93102
/// of type are accessed/created with MF::getInfo and destroyed when the

llvm/include/llvm/CodeGen/MachineJumpTableInfo.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ namespace llvm {
2828
class MachineBasicBlock;
2929
class DataLayout;
3030
class raw_ostream;
31+
enum class DataHotness;
3132

3233
/// MachineJumpTableEntry - One jump table in the jump table info.
3334
///
3435
struct MachineJumpTableEntry {
3536
/// MBBs - The vector of basic blocks from which to create the jump table.
3637
std::vector<MachineBasicBlock*> MBBs;
3738

38-
explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock*> &M)
39-
: MBBs(M) {}
39+
DataHotness Hotness;
40+
41+
explicit MachineJumpTableEntry(const std::vector<MachineBasicBlock *> &M);
4042
};
4143

4244
class MachineJumpTableInfo {
@@ -107,6 +109,8 @@ class MachineJumpTableInfo {
107109
return JumpTables;
108110
}
109111

112+
void updateJumpTableHotness(size_t JTI, DataHotness Hotness);
113+
110114
/// RemoveJumpTable - Mark the specific index as being dead. This will
111115
/// prevent it from being emitted.
112116
void RemoveJumpTable(unsigned Idx) {

llvm/include/llvm/CodeGen/Passes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ namespace llvm {
7171
/// using profile information.
7272
MachineFunctionPass *createMachineFunctionSplitterPass();
7373

74+
/// createStaticDataSplitterPass - This pass partions static data sections
75+
/// into a hot and cold section using profile information.
76+
MachineFunctionPass *createStaticDataSplitterPass();
77+
7478
/// MachineFunctionPrinter pass - This pass prints out the machine function to
7579
/// the given stream as a debugging tool.
7680
MachineFunctionPass *

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ void initializeSpeculativeExecutionLegacyPassPass(PassRegistry &);
293293
void initializeSpillPlacementWrapperLegacyPass(PassRegistry &);
294294
void initializeStackColoringLegacyPass(PassRegistry &);
295295
void initializeStackFrameLayoutAnalysisPassPass(PassRegistry &);
296+
void initializeStaticDataSplitterPass(PassRegistry &);
296297
void initializeStackMapLivenessPass(PassRegistry &);
297298
void initializeStackProtectorPass(PassRegistry &);
298299
void initializeStackSafetyGlobalInfoWrapperPassPass(PassRegistry &);

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ DUMMY_MACHINE_FUNCTION_PASS("livedebugvalues", LiveDebugValuesPass)
236236
DUMMY_MACHINE_FUNCTION_PASS("lrshrink", LiveRangeShrinkPass)
237237
DUMMY_MACHINE_FUNCTION_PASS("machine-combiner", MachineCombinerPass)
238238
DUMMY_MACHINE_FUNCTION_PASS("machine-cp", MachineCopyPropagationPass)
239+
DUMMY_MACHINE_FUNCTION_PASS("static-data-splitter", StaticDataSplitter)
239240
DUMMY_MACHINE_FUNCTION_PASS("machine-function-splitter", MachineFunctionSplitterPass)
240241
DUMMY_MACHINE_FUNCTION_PASS("machine-latecleanup", MachineLateInstrsCleanupPass)
241242
DUMMY_MACHINE_FUNCTION_PASS("machine-sanmd", MachineSanitizerBinaryMetadata)

llvm/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ add_llvm_component_library(LLVMCodeGen
226226
StackMaps.cpp
227227
StackProtector.cpp
228228
StackSlotColoring.cpp
229+
StaticDataSplitter.cpp
229230
SwiftErrorValueTracking.cpp
230231
SwitchLoweringUtils.cpp
231232
TailDuplication.cpp

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
130130
initializeStackMapLivenessPass(Registry);
131131
initializeStackProtectorPass(Registry);
132132
initializeStackSlotColoringPass(Registry);
133+
initializeStaticDataSplitterPass(Registry);
133134
initializeStripDebugMachineModulePass(Registry);
134135
initializeTailDuplicateLegacyPass(Registry);
135136
initializeTargetPassConfigPass(Registry);

llvm/lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,10 @@ bool MachineBasicBlock::canSplitCriticalEdge(
14261426
return true;
14271427
}
14281428

1429+
int MachineBasicBlock::getJumpTableIndex() const {
1430+
return findJumpTableIndex(*this);
1431+
}
1432+
14291433
/// Prepare MI to be removed from its bundle. This fixes bundle flags on MI's
14301434
/// neighboring instructions so the bundle won't be broken by removing MI.
14311435
static void unbundleSingleMI(MachineInstr *MI) {

llvm/lib/CodeGen/MachineFunction.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,10 @@ const unsigned MachineFunction::DebugOperandMemNumber = 1000000;
12911291
// MachineJumpTableInfo implementation
12921292
//===----------------------------------------------------------------------===//
12931293

1294+
MachineJumpTableEntry::MachineJumpTableEntry(
1295+
const std::vector<MachineBasicBlock *> &MBBs)
1296+
: MBBs(MBBs), Hotness(DataHotness::Unknown) {}
1297+
12941298
/// Return the size of each entry in the jump table.
12951299
unsigned MachineJumpTableInfo::getEntrySize(const DataLayout &TD) const {
12961300
// The size of a jump table entry is 4 bytes unless the entry is just the
@@ -1340,6 +1344,15 @@ unsigned MachineJumpTableInfo::createJumpTableIndex(
13401344
return JumpTables.size()-1;
13411345
}
13421346

1347+
void MachineJumpTableInfo::updateJumpTableHotness(size_t JTI,
1348+
DataHotness Hotness) {
1349+
assert(JTI < JumpTables.size() && "Invalid JTI!");
1350+
// Note record the largest hotness is important for mergable data (constant
1351+
// pools). Even if jump table instances are not merged, record the largest
1352+
// value seen fwiw.
1353+
JumpTables[JTI].Hotness = std::max(JumpTables[JTI].Hotness, Hotness);
1354+
}
1355+
13431356
/// If Old is the target of any jump tables, update the jump tables to branch
13441357
/// to New instead.
13451358
bool MachineJumpTableInfo::ReplaceMBBInJumpTables(MachineBasicBlock *Old,

0 commit comments

Comments
 (0)