================ @@ -2876,42 +2875,101 @@ void AsmPrinter::emitJumpTableInfo() { MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference32 || MJTI->getEntryKind() == MachineJumpTableInfo::EK_LabelDifference64, F); + + std::vector<unsigned> JumpTableIndices; + if (!TM.Options.EnableStaticDataPartitioning) { + for (unsigned JTI = 0, JTSize = JT.size(); JTI < JTSize; ++JTI) + JumpTableIndices.push_back(JTI); + emitJumpTables(JumpTableIndices, TLOF.getSectionForJumpTable(F, TM), + JTInDiffSection, *MJTI); + return; + } + + // When static data partitioning is enabled, collect jump table entries that + // go into the same section together to reduce the amount of section switch + // statements. + // + // Iterate all jump tables, put hot jump table indices towards the beginning + // of the vector, and cold jump table indices towards the end. Meanwhile + // retain the relative orders of original jump tables within a hot or unlikely + // section by reversing the cold jump table indices. + int NextHotJumpTableIndex = 0, NextColdJumpTableIndex = JT.size() - 1; + JumpTableIndices.resize(JT.size()); + for (unsigned JTI = 0, JTSize = JT.size(); JTI < JTSize; ++JTI) { + if (JT[JTI].Hotness == MachineFunctionDataHotness::Cold) + JumpTableIndices[NextColdJumpTableIndex--] = JTI; + else + JumpTableIndices[NextHotJumpTableIndex++] = JTI; + } + + if (NextHotJumpTableIndex != 0) { + emitJumpTables( + ArrayRef<unsigned>(JumpTableIndices).take_front(NextHotJumpTableIndex), + TLOF.getSectionForJumpTable(F, TM, &JT[0]), JTInDiffSection, *MJTI); + } + + if (NextHotJumpTableIndex < (int)JT.size()) { + // Reverse the order of cold jump tables indices. + for (int L = NextHotJumpTableIndex, R = JT.size() - 1; L < R; ++L, --R) + std::swap(JumpTableIndices[L], JumpTableIndices[R]); ---------------- mingmingl-llvm wrote:
This makes sense to not update memory and I like the idea of reverse iterating. I ended up using `llvm::make_range` to specify the iterated range and order, and templated the original `emitJumpTables` method. I also renamed it to `emitJumpTableImpl` and removed `virtual` keyword from it. https://github.com/llvm/llvm-project/pull/122215 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits