@@ -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,94 @@ void AsmPrinter::emitJumpTableInfo() {
2876
2880
MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 ||
2877
2881
MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference64,
2878
2882
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 ();
2879
2933
if (JTInDiffSection) {
2880
- // Drop it in the readonly section.
2881
- MCSection *ReadOnlySection = TLOF.getSectionForJumpTable (F, TM);
2882
- OutStreamer->switchSection (ReadOnlySection);
2934
+ OutStreamer->switchSection (JumpTableSection);
2883
2935
}
2884
2936
2885
- emitAlignment (Align (MJTI-> getEntryAlignment (DL )));
2937
+ emitAlignment (Align (MJTI. getEntryAlignment (MF-> getDataLayout () )));
2886
2938
2887
2939
// Jump tables in code sections are marked with a data_region directive
2888
2940
// where that's supported.
2889
2941
if (!JTInDiffSection)
2890
2942
OutStreamer->emitDataRegion (MCDR_DataRegionJT32);
2891
2943
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 ;
2894
2948
2895
2949
// If this jump table was deleted, ignore it.
2896
- if (JTBBs.empty ()) continue ;
2950
+ if (JTBBs.empty ())
2951
+ continue ;
2897
2952
2898
2953
// For the EK_LabelDifference32 entry, if using .set avoids a relocation,
2899
2954
// / emit a .set directive for each unique entry.
2900
- if (MJTI-> getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
2955
+ if (MJTI. getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
2901
2956
MAI->doesSetDirectiveSuppressReloc ()) {
2902
- SmallPtrSet<const MachineBasicBlock*, 16 > EmittedSets;
2957
+ SmallPtrSet<const MachineBasicBlock *, 16 > EmittedSets;
2903
2958
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);
2905
2961
for (const MachineBasicBlock *MBB : JTBBs) {
2906
2962
if (!EmittedSets.insert (MBB).second )
2907
2963
continue ;
2908
2964
2909
2965
// .set LJTSet, LBB32-base
2910
2966
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));
2915
2971
}
2916
2972
}
2917
2973
@@ -2923,27 +2979,27 @@ void AsmPrinter::emitJumpTableInfo() {
2923
2979
// FIXME: This doesn't have to have any specific name, just any randomly
2924
2980
// named and numbered local label started with 'l' would work. Simplify
2925
2981
// GetJTISymbol.
2926
- OutStreamer->emitLabel (GetJTISymbol (JTI , true ));
2982
+ OutStreamer->emitLabel (GetJTISymbol (JumpTableIndices[Index] , true ));
2927
2983
2928
- MCSymbol* JTISymbol = GetJTISymbol (JTI );
2984
+ MCSymbol * JTISymbol = GetJTISymbol (JumpTableIndices[Index] );
2929
2985
OutStreamer->emitLabel (JTISymbol);
2930
2986
2931
2987
// Defer MCAssembler based constant folding due to a performance issue. The
2932
2988
// label differences will be evaluated at write time.
2933
2989
for (const MachineBasicBlock *MBB : JTBBs)
2934
- emitJumpTableEntry (MJTI, MBB, JTI );
2990
+ emitJumpTableEntry (MJTI, MBB, JumpTableIndices[Index] );
2935
2991
}
2936
2992
2937
2993
if (EmitJumpTableSizesSection)
2938
- emitJumpTableSizesSection (MJTI, F );
2994
+ emitJumpTableSizesSection (MJTI, MF-> getFunction () );
2939
2995
2940
2996
if (!JTInDiffSection)
2941
2997
OutStreamer->emitDataRegion (MCDR_DataRegionEnd);
2942
2998
}
2943
2999
2944
- void AsmPrinter::emitJumpTableSizesSection (const MachineJumpTableInfo * MJTI,
3000
+ void AsmPrinter::emitJumpTableSizesSection (const MachineJumpTableInfo & MJTI,
2945
3001
const Function &F) const {
2946
- const std::vector<MachineJumpTableEntry> &JT = MJTI-> getJumpTables ();
3002
+ const std::vector<MachineJumpTableEntry> &JT = MJTI. getJumpTables ();
2947
3003
2948
3004
if (JT.empty ())
2949
3005
return ;
@@ -2991,17 +3047,17 @@ void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo *MJTI,
2991
3047
2992
3048
// / EmitJumpTableEntry - Emit a jump table entry for the specified MBB to the
2993
3049
// / current stream.
2994
- void AsmPrinter::emitJumpTableEntry (const MachineJumpTableInfo * MJTI,
3050
+ void AsmPrinter::emitJumpTableEntry (const MachineJumpTableInfo & MJTI,
2995
3051
const MachineBasicBlock *MBB,
2996
3052
unsigned UID) const {
2997
3053
assert (MBB && MBB->getNumber () >= 0 && " Invalid basic block" );
2998
3054
const MCExpr *Value = nullptr ;
2999
- switch (MJTI-> getEntryKind ()) {
3055
+ switch (MJTI. getEntryKind ()) {
3000
3056
case MachineJumpTableInfo::EK_Inline:
3001
3057
llvm_unreachable (" Cannot emit EK_Inline jump table entry" );
3002
3058
case MachineJumpTableInfo::EK_Custom32:
3003
3059
Value = MF->getSubtarget ().getTargetLowering ()->LowerCustomJumpTableEntry (
3004
- MJTI, MBB, UID, OutContext);
3060
+ & MJTI, MBB, UID, OutContext);
3005
3061
break ;
3006
3062
case MachineJumpTableInfo::EK_BlockAddress:
3007
3063
// EK_BlockAddress - Each entry is a plain address of block, e.g.:
@@ -3035,7 +3091,7 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo *MJTI,
3035
3091
// If the .set directive avoids relocations, this is emitted as:
3036
3092
// .set L4_5_set_123, LBB123 - LJTI1_2
3037
3093
// .word L4_5_set_123
3038
- if (MJTI-> getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
3094
+ if (MJTI. getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
3039
3095
MAI->doesSetDirectiveSuppressReloc ()) {
3040
3096
Value = MCSymbolRefExpr::create (GetJTSetSymbol (UID, MBB->getNumber ()),
3041
3097
OutContext);
@@ -3051,7 +3107,7 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo *MJTI,
3051
3107
3052
3108
assert (Value && " Unknown entry kind!" );
3053
3109
3054
- unsigned EntrySize = MJTI-> getEntrySize (getDataLayout ());
3110
+ unsigned EntrySize = MJTI. getEntrySize (getDataLayout ());
3055
3111
OutStreamer->emitValue (Value, EntrySize);
3056
3112
}
3057
3113
0 commit comments