@@ -2881,42 +2881,41 @@ void AsmPrinter::emitJumpTableInfo() {
28812881 MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference64,
28822882 F);
28832883
2884+ std::vector<unsigned > JumpTableIndices;
2885+ for (unsigned JTI = 0 , JTSize = JT.size (); JTI != JTSize; ++JTI)
2886+ JumpTableIndices.push_back (JTI);
28842887 if (!EmitStaticDataHotnessSuffix) {
2885- std::vector<unsigned > JumpTableIndices;
2886- for (unsigned JTI = 0 , e = JT.size (); JTI != e; ++JTI)
2887- JumpTableIndices.push_back (JTI);
2888- // Prior code in this function verifies JT is not empty. Use JT[0] directly.
28892888 emitJumpTables (JumpTableIndices, TLOF.getSectionForJumpTable (F, TM),
28902889 JTInDiffSection, *MJTI);
28912890 return ;
28922891 }
28932892
2894- // Iterate all jump tables, put them into two vectors, hot and lukewarm
2895- std::vector<unsigned > HotOrWarmJumpTableIndices, ColdJumpTableIndices;
2896-
2897- for (unsigned JTI = 0 , e = JT.size (); JTI != e; ++JTI) {
2898- if (JT[JTI].Hotness == llvm::DataHotness::Cold)
2899- ColdJumpTableIndices.push_back (JTI);
2900- else
2901- HotOrWarmJumpTableIndices.push_back (JTI);
2893+ // Iterate all jump tables, put hot jump table indices towards the beginning
2894+ // of the vector, and cold jump table indices towards the end.
2895+ unsigned ColdJumpTableStart = JT.size ();
2896+ for (unsigned JTI = 0 ; JTI != ColdJumpTableStart;) {
2897+ if (JT[JTI].Hotness == llvm::DataHotness::Cold) {
2898+ ColdJumpTableStart -= 1 ;
2899+ std::swap (JumpTableIndices[JTI], JumpTableIndices[ColdJumpTableStart]);
2900+ } else
2901+ JTI += 1 ;
29022902 }
29032903
2904- if (!HotOrWarmJumpTableIndices.empty ())
2905- emitJumpTables (HotOrWarmJumpTableIndices,
2906- TLOF.getSectionForJumpTable (
2907- F, TM, &JT[*HotOrWarmJumpTableIndices.begin ()]),
2908- JTInDiffSection, *MJTI);
2904+ if (ColdJumpTableStart != 0 )
2905+ emitJumpTables (
2906+ ArrayRef<unsigned >(JumpTableIndices).slice (0 , ColdJumpTableStart),
2907+ TLOF.getSectionForJumpTable (F, TM, &JT[0 ]), JTInDiffSection, *MJTI);
29092908
2910- if (!ColdJumpTableIndices. empty ())
2909+ if (ColdJumpTableStart != JT. size ())
29112910 emitJumpTables (
2912- ColdJumpTableIndices ,
2913- TLOF.getSectionForJumpTable (F, TM, &JT[*ColdJumpTableIndices. begin () ]),
2911+ ArrayRef< unsigned >(JumpTableIndices). slice (ColdJumpTableStart) ,
2912+ TLOF.getSectionForJumpTable (F, TM, &JT[ColdJumpTableStart ]),
29142913 JTInDiffSection, *MJTI);
29152914
29162915 return ;
29172916}
29182917
2919- void AsmPrinter::emitJumpTables (const std::vector <unsigned > & JumpTableIndices,
2918+ void AsmPrinter::emitJumpTables (ArrayRef <unsigned > JumpTableIndices,
29202919 MCSection *JumpTableSection,
29212920 bool JTInDiffSection,
29222921 const MachineJumpTableInfo &MJTI) {
0 commit comments