@@ -2868,42 +2868,62 @@ void AsmPrinter::emitJumpTableInfo() {
2868
2868
MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 ||
2869
2869
MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference64,
2870
2870
F);
2871
+
2872
+ SmallVector<unsigned > JumpTableIndices;
2873
+ for (unsigned JTI = 0 , JTSize = JT.size (); JTI < JTSize; ++JTI) {
2874
+ JumpTableIndices.push_back (JTI);
2875
+ }
2876
+ emitJumpTableImpl (*MJTI, JumpTableIndices, JTInDiffSection);
2877
+ }
2878
+
2879
+ void AsmPrinter::emitJumpTableImpl (const MachineJumpTableInfo &MJTI,
2880
+ ArrayRef<unsigned > JumpTableIndices,
2881
+ bool JTInDiffSection) {
2882
+ if (JumpTableIndices.empty ())
2883
+ return ;
2884
+
2885
+ const TargetLoweringObjectFile &TLOF = getObjFileLowering ();
2886
+ const Function &F = MF->getFunction ();
2887
+ const std::vector<MachineJumpTableEntry> &JT = MJTI.getJumpTables ();
2888
+ MCSection *JumpTableSection = TLOF.getSectionForJumpTable (F, TM);
2889
+
2890
+ const DataLayout &DL = MF->getDataLayout ();
2871
2891
if (JTInDiffSection) {
2872
- // Drop it in the readonly section.
2873
- MCSection *ReadOnlySection = TLOF.getSectionForJumpTable (F, TM);
2874
- OutStreamer->switchSection (ReadOnlySection);
2892
+ OutStreamer->switchSection (JumpTableSection);
2875
2893
}
2876
2894
2877
- emitAlignment (Align (MJTI-> getEntryAlignment (DL )));
2895
+ emitAlignment (Align (MJTI. getEntryAlignment (MF-> getDataLayout () )));
2878
2896
2879
2897
// Jump tables in code sections are marked with a data_region directive
2880
2898
// where that's supported.
2881
2899
if (!JTInDiffSection)
2882
2900
OutStreamer->emitDataRegion (MCDR_DataRegionJT32);
2883
2901
2884
- for (unsigned JTI = 0 , e = JT. size (); JTI != e; ++JTI ) {
2885
- const std::vector <MachineBasicBlock*> & JTBBs = JT[JTI ].MBBs ;
2902
+ for (const unsigned JumpTableIndex : JumpTableIndices ) {
2903
+ ArrayRef <MachineBasicBlock *> JTBBs = JT[JumpTableIndex ].MBBs ;
2886
2904
2887
2905
// If this jump table was deleted, ignore it.
2888
- if (JTBBs.empty ()) continue ;
2906
+ if (JTBBs.empty ())
2907
+ continue ;
2889
2908
2890
2909
// For the EK_LabelDifference32 entry, if using .set avoids a relocation,
2891
2910
// / emit a .set directive for each unique entry.
2892
- if (MJTI-> getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
2911
+ if (MJTI. getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
2893
2912
MAI->doesSetDirectiveSuppressReloc ()) {
2894
- SmallPtrSet<const MachineBasicBlock*, 16 > EmittedSets;
2913
+ SmallPtrSet<const MachineBasicBlock *, 16 > EmittedSets;
2895
2914
const TargetLowering *TLI = MF->getSubtarget ().getTargetLowering ();
2896
- const MCExpr *Base = TLI->getPICJumpTableRelocBaseExpr (MF,JTI,OutContext);
2915
+ const MCExpr *Base =
2916
+ TLI->getPICJumpTableRelocBaseExpr (MF, JumpTableIndex, OutContext);
2897
2917
for (const MachineBasicBlock *MBB : JTBBs) {
2898
2918
if (!EmittedSets.insert (MBB).second )
2899
2919
continue ;
2900
2920
2901
2921
// .set LJTSet, LBB32-base
2902
2922
const MCExpr *LHS =
2903
- MCSymbolRefExpr::create (MBB->getSymbol (), OutContext);
2904
- OutStreamer->emitAssignment (GetJTSetSymbol (JTI, MBB-> getNumber ()),
2905
- MCBinaryExpr::createSub (LHS, Base ,
2906
- OutContext));
2923
+ MCSymbolRefExpr::create (MBB->getSymbol (), OutContext);
2924
+ OutStreamer->emitAssignment (
2925
+ GetJTSetSymbol (JumpTableIndex, MBB-> getNumber ()) ,
2926
+ MCBinaryExpr::createSub (LHS, Base, OutContext));
2907
2927
}
2908
2928
}
2909
2929
@@ -2915,19 +2935,19 @@ void AsmPrinter::emitJumpTableInfo() {
2915
2935
// FIXME: This doesn't have to have any specific name, just any randomly
2916
2936
// named and numbered local label started with 'l' would work. Simplify
2917
2937
// GetJTISymbol.
2918
- OutStreamer->emitLabel (GetJTISymbol (JTI , true ));
2938
+ OutStreamer->emitLabel (GetJTISymbol (JumpTableIndex , true ));
2919
2939
2920
- MCSymbol* JTISymbol = GetJTISymbol (JTI );
2940
+ MCSymbol * JTISymbol = GetJTISymbol (JumpTableIndex );
2921
2941
OutStreamer->emitLabel (JTISymbol);
2922
2942
2923
2943
// Defer MCAssembler based constant folding due to a performance issue. The
2924
2944
// label differences will be evaluated at write time.
2925
2945
for (const MachineBasicBlock *MBB : JTBBs)
2926
- emitJumpTableEntry (* MJTI, MBB, JTI );
2946
+ emitJumpTableEntry (MJTI, MBB, JumpTableIndex );
2927
2947
}
2928
2948
2929
2949
if (EmitJumpTableSizesSection)
2930
- emitJumpTableSizesSection (* MJTI, F );
2950
+ emitJumpTableSizesSection (MJTI, MF-> getFunction () );
2931
2951
2932
2952
if (!JTInDiffSection)
2933
2953
OutStreamer->emitDataRegion (MCDR_DataRegionEnd);
0 commit comments