@@ -247,6 +247,17 @@ static bool supportLoadFromLiteral(const MachineInstr &MI) {
247
247
}
248
248
}
249
249
250
+ // / Returns \p true if there are no non-debug instructions between \p First and
251
+ // / \p Second
252
+ static bool areInstructionsConsecutive (const MachineInstr *First,
253
+ const MachineInstr *Second) {
254
+ auto It = First->getIterator ();
255
+ auto EndIt = First->getParent ()->instr_end ();
256
+ if (It == EndIt)
257
+ return false ;
258
+ return next_nodbg (It, EndIt) == Second->getIterator ();
259
+ }
260
+
250
261
// / Number of GPR registers tracked by mapRegToGPRIndex()
251
262
static const unsigned N_GPR_REGS = 31 ;
252
263
// / Map register number to index from 0-30.
@@ -415,7 +426,7 @@ static void handleADRP(const MachineInstr &MI, AArch64FunctionInfo &AFI,
415
426
++NumADRPToLDR;
416
427
}
417
428
break ;
418
- case MCLOH_AdrpAddLdr: {
429
+ case MCLOH_AdrpAddLdr:
419
430
// There is a possibility that the linker may try to rewrite:
420
431
// adrp x0, @sym@PAGE
421
432
// add x1, x0, @sym@PAGEOFF
@@ -432,28 +443,24 @@ static void handleADRP(const MachineInstr &MI, AArch64FunctionInfo &AFI,
432
443
// FIXME: Implement proper liveness tracking for all registers. For now,
433
444
// don't emit the LOH if there are any instructions between the add and
434
445
// the ldr.
435
- MachineInstr *AddMI = const_cast <MachineInstr *>(Info.MI1 );
436
- const MachineInstr *LdrMI = Info.MI0 ;
437
- auto AddIt = MachineBasicBlock::iterator (AddMI);
438
- auto EndIt = AddMI->getParent ()->end ();
439
- if (AddMI->getIterator () == EndIt || LdrMI != &*next_nodbg (AddIt, EndIt))
446
+ if (!areInstructionsConsecutive (Info.MI1 , Info.MI0 ))
440
447
break ;
441
-
442
448
LLVM_DEBUG (dbgs () << " Adding MCLOH_AdrpAddLdr:\n "
443
449
<< ' \t ' << MI << ' \t ' << *Info.MI1 << ' \t '
444
450
<< *Info.MI0 );
445
451
AFI.addLOHDirective (MCLOH_AdrpAddLdr, {&MI, Info.MI1 , Info.MI0 });
446
452
++NumADDToLDR;
447
453
break ;
448
- }
449
454
case MCLOH_AdrpAddStr:
450
- if (Info.MI1 != nullptr ) {
451
- LLVM_DEBUG (dbgs () << " Adding MCLOH_AdrpAddStr:\n "
452
- << ' \t ' << MI << ' \t ' << *Info.MI1 << ' \t '
453
- << *Info.MI0 );
454
- AFI.addLOHDirective (MCLOH_AdrpAddStr, {&MI, Info.MI1 , Info.MI0 });
455
- ++NumADDToSTR;
456
- }
455
+ if (!Info.MI1 )
456
+ break ;
457
+ if (!areInstructionsConsecutive (Info.MI1 , Info.MI0 ))
458
+ break ;
459
+ LLVM_DEBUG (dbgs () << " Adding MCLOH_AdrpAddStr:\n "
460
+ << ' \t ' << MI << ' \t ' << *Info.MI1 << ' \t '
461
+ << *Info.MI0 );
462
+ AFI.addLOHDirective (MCLOH_AdrpAddStr, {&MI, Info.MI1 , Info.MI0 });
463
+ ++NumADDToSTR;
457
464
break ;
458
465
case MCLOH_AdrpLdrGotLdr:
459
466
LLVM_DEBUG (dbgs () << " Adding MCLOH_AdrpLdrGotLdr:\n "
0 commit comments