@@ -168,6 +168,11 @@ static cl::opt<bool> BBAddrMapSkipEmitBBEntries(
168
168
" unnecessary for some PGOAnalysisMap features." ),
169
169
cl::Hidden, cl::init(false ));
170
170
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
+
171
176
static cl::opt<bool > EmitJumpTableSizesSection (
172
177
" emit-jump-table-sizes-section" ,
173
178
cl::desc (" Emit a section containing jump table addresses and sizes" ),
@@ -2861,7 +2866,6 @@ void AsmPrinter::emitConstantPool() {
2861
2866
// Print assembly representations of the jump tables used by the current
2862
2867
// function.
2863
2868
void AsmPrinter::emitJumpTableInfo () {
2864
- const DataLayout &DL = MF->getDataLayout ();
2865
2869
const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo ();
2866
2870
if (!MJTI) return ;
2867
2871
if (MJTI->getEntryKind () == MachineJumpTableInfo::EK_Inline) return ;
@@ -2876,42 +2880,88 @@ void AsmPrinter::emitJumpTableInfo() {
2876
2880
MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 ||
2877
2881
MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference64,
2878
2882
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 ();
2879
2927
if (JTInDiffSection) {
2880
- // Drop it in the readonly section.
2881
- MCSection *ReadOnlySection = TLOF.getSectionForJumpTable (F, TM);
2882
- OutStreamer->switchSection (ReadOnlySection);
2928
+ OutStreamer->switchSection (JumpTableSection);
2883
2929
}
2884
2930
2885
- emitAlignment (Align (MJTI-> getEntryAlignment (DL )));
2931
+ emitAlignment (Align (MJTI. getEntryAlignment (MF-> getDataLayout () )));
2886
2932
2887
2933
// Jump tables in code sections are marked with a data_region directive
2888
2934
// where that's supported.
2889
2935
if (!JTInDiffSection)
2890
2936
OutStreamer->emitDataRegion (MCDR_DataRegionJT32);
2891
2937
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 ;
2894
2942
2895
2943
// If this jump table was deleted, ignore it.
2896
- if (JTBBs.empty ()) continue ;
2944
+ if (JTBBs.empty ())
2945
+ continue ;
2897
2946
2898
2947
// For the EK_LabelDifference32 entry, if using .set avoids a relocation,
2899
2948
// / emit a .set directive for each unique entry.
2900
- if (MJTI-> getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
2949
+ if (MJTI. getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
2901
2950
MAI->doesSetDirectiveSuppressReloc ()) {
2902
- SmallPtrSet<const MachineBasicBlock*, 16 > EmittedSets;
2951
+ SmallPtrSet<const MachineBasicBlock *, 16 > EmittedSets;
2903
2952
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);
2905
2955
for (const MachineBasicBlock *MBB : JTBBs) {
2906
2956
if (!EmittedSets.insert (MBB).second )
2907
2957
continue ;
2908
2958
2909
2959
// .set LJTSet, LBB32-base
2910
2960
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));
2915
2965
}
2916
2966
}
2917
2967
@@ -2923,27 +2973,27 @@ void AsmPrinter::emitJumpTableInfo() {
2923
2973
// FIXME: This doesn't have to have any specific name, just any randomly
2924
2974
// named and numbered local label started with 'l' would work. Simplify
2925
2975
// GetJTISymbol.
2926
- OutStreamer->emitLabel (GetJTISymbol (JTI , true ));
2976
+ OutStreamer->emitLabel (GetJTISymbol (JumpTableIndices[Index] , true ));
2927
2977
2928
- MCSymbol* JTISymbol = GetJTISymbol (JTI );
2978
+ MCSymbol * JTISymbol = GetJTISymbol (JumpTableIndices[Index] );
2929
2979
OutStreamer->emitLabel (JTISymbol);
2930
2980
2931
2981
// Defer MCAssembler based constant folding due to a performance issue. The
2932
2982
// label differences will be evaluated at write time.
2933
2983
for (const MachineBasicBlock *MBB : JTBBs)
2934
- emitJumpTableEntry (MJTI, MBB, JTI );
2984
+ emitJumpTableEntry (MJTI, MBB, JumpTableIndices[Index] );
2935
2985
}
2936
2986
2937
2987
if (EmitJumpTableSizesSection)
2938
- emitJumpTableSizesSection (MJTI, F );
2988
+ emitJumpTableSizesSection (MJTI, MF-> getFunction () );
2939
2989
2940
2990
if (!JTInDiffSection)
2941
2991
OutStreamer->emitDataRegion (MCDR_DataRegionEnd);
2942
2992
}
2943
2993
2944
- void AsmPrinter::emitJumpTableSizesSection (const MachineJumpTableInfo * MJTI,
2994
+ void AsmPrinter::emitJumpTableSizesSection (const MachineJumpTableInfo & MJTI,
2945
2995
const Function &F) const {
2946
- const std::vector<MachineJumpTableEntry> &JT = MJTI-> getJumpTables ();
2996
+ const std::vector<MachineJumpTableEntry> &JT = MJTI. getJumpTables ();
2947
2997
2948
2998
if (JT.empty ())
2949
2999
return ;
@@ -2991,17 +3041,17 @@ void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo *MJTI,
2991
3041
2992
3042
// / EmitJumpTableEntry - Emit a jump table entry for the specified MBB to the
2993
3043
// / current stream.
2994
- void AsmPrinter::emitJumpTableEntry (const MachineJumpTableInfo * MJTI,
3044
+ void AsmPrinter::emitJumpTableEntry (const MachineJumpTableInfo & MJTI,
2995
3045
const MachineBasicBlock *MBB,
2996
3046
unsigned UID) const {
2997
3047
assert (MBB && MBB->getNumber () >= 0 && " Invalid basic block" );
2998
3048
const MCExpr *Value = nullptr ;
2999
- switch (MJTI-> getEntryKind ()) {
3049
+ switch (MJTI. getEntryKind ()) {
3000
3050
case MachineJumpTableInfo::EK_Inline:
3001
3051
llvm_unreachable (" Cannot emit EK_Inline jump table entry" );
3002
3052
case MachineJumpTableInfo::EK_Custom32:
3003
3053
Value = MF->getSubtarget ().getTargetLowering ()->LowerCustomJumpTableEntry (
3004
- MJTI, MBB, UID, OutContext);
3054
+ & MJTI, MBB, UID, OutContext);
3005
3055
break ;
3006
3056
case MachineJumpTableInfo::EK_BlockAddress:
3007
3057
// EK_BlockAddress - Each entry is a plain address of block, e.g.:
@@ -3035,7 +3085,7 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo *MJTI,
3035
3085
// If the .set directive avoids relocations, this is emitted as:
3036
3086
// .set L4_5_set_123, LBB123 - LJTI1_2
3037
3087
// .word L4_5_set_123
3038
- if (MJTI-> getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
3088
+ if (MJTI. getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
3039
3089
MAI->doesSetDirectiveSuppressReloc ()) {
3040
3090
Value = MCSymbolRefExpr::create (GetJTSetSymbol (UID, MBB->getNumber ()),
3041
3091
OutContext);
@@ -3051,7 +3101,7 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo *MJTI,
3051
3101
3052
3102
assert (Value && " Unknown entry kind!" );
3053
3103
3054
- unsigned EntrySize = MJTI-> getEntrySize (getDataLayout ());
3104
+ unsigned EntrySize = MJTI. getEntrySize (getDataLayout ());
3055
3105
OutStreamer->emitValue (Value, EntrySize);
3056
3106
}
3057
3107
0 commit comments