@@ -2868,42 +2868,62 @@ void AsmPrinter::emitJumpTableInfo() {
28682868 MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 ||
28692869 MJTI->getEntryKind () == MachineJumpTableInfo::EK_LabelDifference64,
28702870 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 ();
28712891 if (JTInDiffSection) {
2872- // Drop it in the readonly section.
2873- MCSection *ReadOnlySection = TLOF.getSectionForJumpTable (F, TM);
2874- OutStreamer->switchSection (ReadOnlySection);
2892+ OutStreamer->switchSection (JumpTableSection);
28752893 }
28762894
2877- emitAlignment (Align (MJTI-> getEntryAlignment (DL )));
2895+ emitAlignment (Align (MJTI. getEntryAlignment (MF-> getDataLayout () )));
28782896
28792897 // Jump tables in code sections are marked with a data_region directive
28802898 // where that's supported.
28812899 if (!JTInDiffSection)
28822900 OutStreamer->emitDataRegion (MCDR_DataRegionJT32);
28832901
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 ;
28862904
28872905 // If this jump table was deleted, ignore it.
2888- if (JTBBs.empty ()) continue ;
2906+ if (JTBBs.empty ())
2907+ continue ;
28892908
28902909 // For the EK_LabelDifference32 entry, if using .set avoids a relocation,
28912910 // / emit a .set directive for each unique entry.
2892- if (MJTI-> getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
2911+ if (MJTI. getEntryKind () == MachineJumpTableInfo::EK_LabelDifference32 &&
28932912 MAI->doesSetDirectiveSuppressReloc ()) {
2894- SmallPtrSet<const MachineBasicBlock*, 16 > EmittedSets;
2913+ SmallPtrSet<const MachineBasicBlock *, 16 > EmittedSets;
28952914 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);
28972917 for (const MachineBasicBlock *MBB : JTBBs) {
28982918 if (!EmittedSets.insert (MBB).second )
28992919 continue ;
29002920
29012921 // .set LJTSet, LBB32-base
29022922 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));
29072927 }
29082928 }
29092929
@@ -2915,19 +2935,19 @@ void AsmPrinter::emitJumpTableInfo() {
29152935 // FIXME: This doesn't have to have any specific name, just any randomly
29162936 // named and numbered local label started with 'l' would work. Simplify
29172937 // GetJTISymbol.
2918- OutStreamer->emitLabel (GetJTISymbol (JTI , true ));
2938+ OutStreamer->emitLabel (GetJTISymbol (JumpTableIndex , true ));
29192939
2920- MCSymbol* JTISymbol = GetJTISymbol (JTI );
2940+ MCSymbol * JTISymbol = GetJTISymbol (JumpTableIndex );
29212941 OutStreamer->emitLabel (JTISymbol);
29222942
29232943 // Defer MCAssembler based constant folding due to a performance issue. The
29242944 // label differences will be evaluated at write time.
29252945 for (const MachineBasicBlock *MBB : JTBBs)
2926- emitJumpTableEntry (* MJTI, MBB, JTI );
2946+ emitJumpTableEntry (MJTI, MBB, JumpTableIndex );
29272947 }
29282948
29292949 if (EmitJumpTableSizesSection)
2930- emitJumpTableSizesSection (* MJTI, F );
2950+ emitJumpTableSizesSection (MJTI, MF-> getFunction () );
29312951
29322952 if (!JTInDiffSection)
29332953 OutStreamer->emitDataRegion (MCDR_DataRegionEnd);
0 commit comments