@@ -168,6 +168,11 @@ static cl::opt<bool> BBAddrMapSkipEmitBBEntries(
168168 " unnecessary for some PGOAnalysisMap features." ),
169169 cl::Hidden, cl::init(false ));
170170
171+ static cl::opt<bool >
172+ EmitStaticDataHotnessSuffix (" emit-static-data-hotness-suffix" , cl::Hidden,
173+ cl::init (false ), cl::ZeroOrMore,
174+ cl::desc(" Emit static data hotness suffix" ));
175+
171176static cl::opt<bool > EmitJumpTableSizesSection (
172177 " emit-jump-table-sizes-section" ,
173178 cl::desc (" Emit a section containing jump table addresses and sizes" ),
@@ -2861,7 +2866,6 @@ void AsmPrinter::emitConstantPool() {
28612866// Print assembly representations of the jump tables used by the current
28622867// function.
28632868void AsmPrinter::emitJumpTableInfo () {
2864- const DataLayout &DL = MF->getDataLayout ();
28652869 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo ();
28662870 if (!MJTI) return ;
28672871 if (MJTI->getEntryKind () == MachineJumpTableInfo::EK_Inline) return ;
@@ -2876,42 +2880,94 @@ void AsmPrinter::emitJumpTableInfo() {
28762880 MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 ||
28772881 MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference64,
28782882 F);
2883+
2884+ std::vector<unsigned > JumpTableIndices;
2885+ if (!EmitStaticDataHotnessSuffix) {
2886+ for (unsigned JTI = 0 , JTSize = JT.size (); JTI < JTSize; ++JTI)
2887+ JumpTableIndices.push_back (JTI);
2888+ emitJumpTables (JumpTableIndices, TLOF.getSectionForJumpTable (F, TM),
2889+ JTInDiffSection, *MJTI);
2890+ return ;
2891+ }
2892+
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+ int NextHotJumpTableIndex = 0 , NextColdJumpTableIndex = JT.size () - 1 ;
2896+ JumpTableIndices.resize (JT.size ());
2897+ for (unsigned JTI = 0 , JTSize = JT.size (); JTI < JTSize; ++JTI) {
2898+ if (JT[JTI].Hotness == MachineFunctionDataHotness::Cold)
2899+ JumpTableIndices[NextColdJumpTableIndex--] = JTI;
2900+ else
2901+ JumpTableIndices[NextHotJumpTableIndex++] = JTI;
2902+ }
2903+
2904+ if (NextHotJumpTableIndex != 0 ) {
2905+ emitJumpTables (
2906+ ArrayRef<unsigned >(JumpTableIndices).take_front (NextHotJumpTableIndex),
2907+ TLOF.getSectionForJumpTable (F, TM, &JT[0 ]), JTInDiffSection, *MJTI);
2908+ }
2909+
2910+ if (NextHotJumpTableIndex != (int )JT.size ()) {
2911+ // Retain the relative orders of original jump tables.
2912+ for (int L = NextHotJumpTableIndex, R = JT.size () - 1 ; L < R; ++L, --R)
2913+ std::swap (JumpTableIndices[L], JumpTableIndices[R]);
2914+
2915+ emitJumpTables (
2916+ ArrayRef<unsigned >(JumpTableIndices)
2917+ .take_back (JT.size () - NextHotJumpTableIndex),
2918+ TLOF.getSectionForJumpTable (F, TM, &JT[JumpTableIndices[NextHotJumpTableIndex]]),
2919+ JTInDiffSection, *MJTI);
2920+ }
2921+
2922+ return ;
2923+ }
2924+
2925+ void AsmPrinter::emitJumpTables (ArrayRef<unsigned > JumpTableIndices,
2926+ MCSection *JumpTableSection,
2927+ bool JTInDiffSection,
2928+ const MachineJumpTableInfo &MJTI) {
2929+ if (JumpTableIndices.empty ())
2930+ return ;
2931+
2932+ const DataLayout &DL = MF->getDataLayout ();
28792933 if (JTInDiffSection) {
2880- // Drop it in the readonly section.
2881- MCSection *ReadOnlySection = TLOF.getSectionForJumpTable (F, TM);
2882- OutStreamer->switchSection (ReadOnlySection);
2934+ OutStreamer->switchSection (JumpTableSection);
28832935 }
28842936
2885- emitAlignment (Align (MJTI-> getEntryAlignment (DL )));
2937+ emitAlignment (Align (MJTI. getEntryAlignment (MF-> getDataLayout () )));
28862938
28872939 // Jump tables in code sections are marked with a data_region directive
28882940 // where that's supported.
28892941 if (!JTInDiffSection)
28902942 OutStreamer->emitDataRegion (MCDR_DataRegionJT32);
28912943
2892- for (unsigned JTI = 0 , e = JT.size (); JTI != e; ++JTI) {
2893- const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs ;
2944+ const auto &JT = MJTI.getJumpTables ();
2945+ for (unsigned Index = 0 , e = JumpTableIndices.size (); Index != e; ++Index) {
2946+ const std::vector<MachineBasicBlock *> &JTBBs =
2947+ JT[JumpTableIndices[Index]].MBBs ;
28942948
28952949 // If this jump table was deleted, ignore it.
2896- if (JTBBs.empty ()) continue ;
2950+ if (JTBBs.empty ())
2951+ continue ;
28972952
28982953 // For the EK_LabelDifference32 entry, if using .set avoids a relocation,
28992954 // / emit a .set directive for each unique entry.
2900- if (MJTI-> getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
2955+ if (MJTI. getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
29012956 MAI->doesSetDirectiveSuppressReloc ()) {
2902- SmallPtrSet<const MachineBasicBlock*, 16 > EmittedSets;
2957+ SmallPtrSet<const MachineBasicBlock *, 16 > EmittedSets;
29032958 const TargetLowering *TLI = MF->getSubtarget ().getTargetLowering ();
2904- const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr (MF,JTI,OutContext);
2959+ const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr (
2960+ MF, JumpTableIndices[Index], OutContext);
29052961 for (const MachineBasicBlock *MBB : JTBBs) {
29062962 if (!EmittedSets.insert (MBB).second )
29072963 continue ;
29082964
29092965 // .set LJTSet, LBB32-base
29102966 const MCExpr *LHS =
2911- MCSymbolRefExpr::create (MBB->getSymbol (), OutContext);
2912- OutStreamer->emitAssignment (GetJTSetSymbol (JTI, MBB-> getNumber ()),
2913- MCBinaryExpr::createSub (LHS, Base ,
2914- OutContext));
2967+ MCSymbolRefExpr::create (MBB->getSymbol (), OutContext);
2968+ OutStreamer->emitAssignment (
2969+ GetJTSetSymbol (JumpTableIndices[Index], MBB-> getNumber ()) ,
2970+ MCBinaryExpr::createSub (LHS, Base, OutContext));
29152971 }
29162972 }
29172973
@@ -2923,27 +2979,27 @@ void AsmPrinter::emitJumpTableInfo() {
29232979 // FIXME: This doesn't have to have any specific name, just any randomly
29242980 // named and numbered local label started with 'l' would work. Simplify
29252981 // GetJTISymbol.
2926- OutStreamer->emitLabel (GetJTISymbol (JTI , true ));
2982+ OutStreamer->emitLabel (GetJTISymbol (JumpTableIndices[Index] , true ));
29272983
2928- MCSymbol* JTISymbol = GetJTISymbol (JTI );
2984+ MCSymbol * JTISymbol = GetJTISymbol (JumpTableIndices[Index] );
29292985 OutStreamer->emitLabel (JTISymbol);
29302986
29312987 // Defer MCAssembler based constant folding due to a performance issue. The
29322988 // label differences will be evaluated at write time.
29332989 for (const MachineBasicBlock *MBB : JTBBs)
2934- emitJumpTableEntry (MJTI, MBB, JTI );
2990+ emitJumpTableEntry (MJTI, MBB, JumpTableIndices[Index] );
29352991 }
29362992
29372993 if (EmitJumpTableSizesSection)
2938- emitJumpTableSizesSection (MJTI, F );
2994+ emitJumpTableSizesSection (MJTI, MF-> getFunction () );
29392995
29402996 if (!JTInDiffSection)
29412997 OutStreamer->emitDataRegion (MCDR_DataRegionEnd);
29422998}
29432999
2944- void AsmPrinter::emitJumpTableSizesSection (const MachineJumpTableInfo * MJTI,
3000+ void AsmPrinter::emitJumpTableSizesSection (const MachineJumpTableInfo & MJTI,
29453001 const Function &F) const {
2946- const std::vector<MachineJumpTableEntry> &JT = MJTI-> getJumpTables ();
3002+ const std::vector<MachineJumpTableEntry> &JT = MJTI. getJumpTables ();
29473003
29483004 if (JT.empty ())
29493005 return ;
@@ -2991,17 +3047,17 @@ void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo *MJTI,
29913047
29923048// / EmitJumpTableEntry - Emit a jump table entry for the specified MBB to the
29933049// / current stream.
2994- void AsmPrinter::emitJumpTableEntry (const MachineJumpTableInfo * MJTI,
3050+ void AsmPrinter::emitJumpTableEntry (const MachineJumpTableInfo & MJTI,
29953051 const MachineBasicBlock *MBB,
29963052 unsigned UID) const {
29973053 assert (MBB && MBB->getNumber () >= 0 && " Invalid basic block" );
29983054 const MCExpr *Value = nullptr ;
2999- switch (MJTI-> getEntryKind ()) {
3055+ switch (MJTI. getEntryKind ()) {
30003056 case MachineJumpTableInfo::EK_Inline:
30013057 llvm_unreachable (" Cannot emit EK_Inline jump table entry" );
30023058 case MachineJumpTableInfo::EK_Custom32:
30033059 Value = MF->getSubtarget ().getTargetLowering ()->LowerCustomJumpTableEntry (
3004- MJTI, MBB, UID, OutContext);
3060+ & MJTI, MBB, UID, OutContext);
30053061 break ;
30063062 case MachineJumpTableInfo::EK_BlockAddress:
30073063 // EK_BlockAddress - Each entry is a plain address of block, e.g.:
@@ -3035,7 +3091,7 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo *MJTI,
30353091 // If the .set directive avoids relocations, this is emitted as:
30363092 // .set L4_5_set_123, LBB123 - LJTI1_2
30373093 // .word L4_5_set_123
3038- if (MJTI-> getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
3094+ if (MJTI. getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
30393095 MAI->doesSetDirectiveSuppressReloc ()) {
30403096 Value = MCSymbolRefExpr::create (GetJTSetSymbol (UID, MBB->getNumber ()),
30413097 OutContext);
@@ -3051,7 +3107,7 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo *MJTI,
30513107
30523108 assert (Value && " Unknown entry kind!" );
30533109
3054- unsigned EntrySize = MJTI-> getEntrySize (getDataLayout ());
3110+ unsigned EntrySize = MJTI. getEntrySize (getDataLayout ());
30553111 OutStreamer->emitValue (Value, EntrySize);
30563112}
30573113
0 commit comments