@@ -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,88 @@ void AsmPrinter::emitJumpTableInfo() {
28762880 MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 ||
28772881 MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference64,
28782882 F);
2883+
2884+ 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.
2889+ emitJumpTables (JumpTableIndices, TLOF.getSectionForJumpTable (F, TM),
2890+ JTInDiffSection, *MJTI);
2891+ return ;
2892+ }
2893+
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);
2902+ }
2903+
2904+ if (!HotOrWarmJumpTableIndices.empty ())
2905+ emitJumpTables (HotOrWarmJumpTableIndices,
2906+ TLOF.getSectionForJumpTable (
2907+ F, TM, &JT[*HotOrWarmJumpTableIndices.begin ()]),
2908+ JTInDiffSection, *MJTI);
2909+
2910+ if (!ColdJumpTableIndices.empty ())
2911+ emitJumpTables (
2912+ ColdJumpTableIndices,
2913+ TLOF.getSectionForJumpTable (F, TM, &JT[*ColdJumpTableIndices.begin ()]),
2914+ JTInDiffSection, *MJTI);
2915+
2916+ return ;
2917+ }
2918+
2919+ void AsmPrinter::emitJumpTables (const std::vector<unsigned > &JumpTableIndices,
2920+ MCSection *JumpTableSection,
2921+ bool JTInDiffSection,
2922+ const MachineJumpTableInfo &MJTI) {
2923+ if (JumpTableIndices.empty ())
2924+ return ;
2925+
2926+ const DataLayout &DL = MF->getDataLayout ();
28792927 if (JTInDiffSection) {
2880- // Drop it in the readonly section.
2881- MCSection *ReadOnlySection = TLOF.getSectionForJumpTable (F, TM);
2882- OutStreamer->switchSection (ReadOnlySection);
2928+ OutStreamer->switchSection (JumpTableSection);
28832929 }
28842930
2885- emitAlignment (Align (MJTI-> getEntryAlignment (DL )));
2931+ emitAlignment (Align (MJTI. getEntryAlignment (MF-> getDataLayout () )));
28862932
28872933 // Jump tables in code sections are marked with a data_region directive
28882934 // where that's supported.
28892935 if (!JTInDiffSection)
28902936 OutStreamer->emitDataRegion (MCDR_DataRegionJT32);
28912937
2892- for (unsigned JTI = 0 , e = JT.size (); JTI != e; ++JTI) {
2893- const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs ;
2938+ const auto &JT = MJTI.getJumpTables ();
2939+ for (unsigned Index = 0 , e = JumpTableIndices.size (); Index != e; ++Index) {
2940+ const std::vector<MachineBasicBlock *> &JTBBs =
2941+ JT[JumpTableIndices[Index]].MBBs ;
28942942
28952943 // If this jump table was deleted, ignore it.
2896- if (JTBBs.empty ()) continue ;
2944+ if (JTBBs.empty ())
2945+ continue ;
28972946
28982947 // For the EK_LabelDifference32 entry, if using .set avoids a relocation,
28992948 // / emit a .set directive for each unique entry.
2900- if (MJTI-> getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
2949+ if (MJTI. getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
29012950 MAI->doesSetDirectiveSuppressReloc ()) {
2902- SmallPtrSet<const MachineBasicBlock*, 16 > EmittedSets;
2951+ SmallPtrSet<const MachineBasicBlock *, 16 > EmittedSets;
29032952 const TargetLowering *TLI = MF->getSubtarget ().getTargetLowering ();
2904- const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr (MF,JTI,OutContext);
2953+ const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr (
2954+ MF, JumpTableIndices[Index], OutContext);
29052955 for (const MachineBasicBlock *MBB : JTBBs) {
29062956 if (!EmittedSets.insert (MBB).second )
29072957 continue ;
29082958
29092959 // .set LJTSet, LBB32-base
29102960 const MCExpr *LHS =
2911- MCSymbolRefExpr::create (MBB->getSymbol (), OutContext);
2912- OutStreamer->emitAssignment (GetJTSetSymbol (JTI, MBB-> getNumber ()),
2913- MCBinaryExpr::createSub (LHS, Base ,
2914- OutContext));
2961+ MCSymbolRefExpr::create (MBB->getSymbol (), OutContext);
2962+ OutStreamer->emitAssignment (
2963+ GetJTSetSymbol (JumpTableIndices[Index], MBB-> getNumber ()) ,
2964+ MCBinaryExpr::createSub (LHS, Base, OutContext));
29152965 }
29162966 }
29172967
@@ -2923,27 +2973,27 @@ void AsmPrinter::emitJumpTableInfo() {
29232973 // FIXME: This doesn't have to have any specific name, just any randomly
29242974 // named and numbered local label started with 'l' would work. Simplify
29252975 // GetJTISymbol.
2926- OutStreamer->emitLabel (GetJTISymbol (JTI , true ));
2976+ OutStreamer->emitLabel (GetJTISymbol (JumpTableIndices[Index] , true ));
29272977
2928- MCSymbol* JTISymbol = GetJTISymbol (JTI );
2978+ MCSymbol * JTISymbol = GetJTISymbol (JumpTableIndices[Index] );
29292979 OutStreamer->emitLabel (JTISymbol);
29302980
29312981 // Defer MCAssembler based constant folding due to a performance issue. The
29322982 // label differences will be evaluated at write time.
29332983 for (const MachineBasicBlock *MBB : JTBBs)
2934- emitJumpTableEntry (MJTI, MBB, JTI );
2984+ emitJumpTableEntry (MJTI, MBB, JumpTableIndices[Index] );
29352985 }
29362986
29372987 if (EmitJumpTableSizesSection)
2938- emitJumpTableSizesSection (MJTI, F );
2988+ emitJumpTableSizesSection (MJTI, MF-> getFunction () );
29392989
29402990 if (!JTInDiffSection)
29412991 OutStreamer->emitDataRegion (MCDR_DataRegionEnd);
29422992}
29432993
2944- void AsmPrinter::emitJumpTableSizesSection (const MachineJumpTableInfo * MJTI,
2994+ void AsmPrinter::emitJumpTableSizesSection (const MachineJumpTableInfo & MJTI,
29452995 const Function &F) const {
2946- const std::vector<MachineJumpTableEntry> &JT = MJTI-> getJumpTables ();
2996+ const std::vector<MachineJumpTableEntry> &JT = MJTI. getJumpTables ();
29472997
29482998 if (JT.empty ())
29492999 return ;
@@ -2991,17 +3041,17 @@ void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo *MJTI,
29913041
29923042// / EmitJumpTableEntry - Emit a jump table entry for the specified MBB to the
29933043// / current stream.
2994- void AsmPrinter::emitJumpTableEntry (const MachineJumpTableInfo * MJTI,
3044+ void AsmPrinter::emitJumpTableEntry (const MachineJumpTableInfo & MJTI,
29953045 const MachineBasicBlock *MBB,
29963046 unsigned UID) const {
29973047 assert (MBB && MBB->getNumber () >= 0 && " Invalid basic block" );
29983048 const MCExpr *Value = nullptr ;
2999- switch (MJTI-> getEntryKind ()) {
3049+ switch (MJTI. getEntryKind ()) {
30003050 case MachineJumpTableInfo::EK_Inline:
30013051 llvm_unreachable (" Cannot emit EK_Inline jump table entry" );
30023052 case MachineJumpTableInfo::EK_Custom32:
30033053 Value = MF->getSubtarget ().getTargetLowering ()->LowerCustomJumpTableEntry (
3004- MJTI, MBB, UID, OutContext);
3054+ & MJTI, MBB, UID, OutContext);
30053055 break ;
30063056 case MachineJumpTableInfo::EK_BlockAddress:
30073057 // EK_BlockAddress - Each entry is a plain address of block, e.g.:
@@ -3035,7 +3085,7 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo *MJTI,
30353085 // If the .set directive avoids relocations, this is emitted as:
30363086 // .set L4_5_set_123, LBB123 - LJTI1_2
30373087 // .word L4_5_set_123
3038- if (MJTI-> getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
3088+ if (MJTI. getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
30393089 MAI->doesSetDirectiveSuppressReloc ()) {
30403090 Value = MCSymbolRefExpr::create (GetJTSetSymbol (UID, MBB->getNumber ()),
30413091 OutContext);
@@ -3051,7 +3101,7 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo *MJTI,
30513101
30523102 assert (Value && " Unknown entry kind!" );
30533103
3054- unsigned EntrySize = MJTI-> getEntrySize (getDataLayout ());
3104+ unsigned EntrySize = MJTI. getEntrySize (getDataLayout ());
30553105 OutStreamer->emitValue (Value, EntrySize);
30563106}
30573107
0 commit comments