@@ -388,36 +388,6 @@ static bool mayHaveInterruptDelaySlot(unsigned InstOpcode) {
388
388
return false ;
389
389
}
390
390
391
- // / Check if the instruction to be emitted is right after any data.
392
- static bool
393
- isRightAfterData (MCFragment *CurrentFragment,
394
- const std::pair<MCFragment *, size_t > &PrevInstPosition) {
395
- MCFragment *F = CurrentFragment;
396
- // Since data is always emitted into a DataFragment, our check strategy is
397
- // simple here.
398
- // - If the fragment is a DataFragment
399
- // - If it's empty (section start or data after align), return false.
400
- // - If it's not the fragment where the previous instruction is,
401
- // returns true.
402
- // - If it's the fragment holding the previous instruction but its
403
- // size changed since the previous instruction was emitted into
404
- // it, returns true.
405
- // - Otherwise returns false.
406
- // - If the fragment is not a DataFragment, returns false.
407
- if (F->getKind () == MCFragment::FT_Data)
408
- return F->getFixedSize () && (F != PrevInstPosition.first ||
409
- F->getFixedSize () != PrevInstPosition.second );
410
-
411
- return false ;
412
- }
413
-
414
- // / \returns the fragment size if it has instructions, otherwise returns 0.
415
- static size_t getSizeForInstFragment (const MCFragment *F) {
416
- if (!F || !F->hasInstructions ())
417
- return 0 ;
418
- return F->getSize ();
419
- }
420
-
421
391
// / Return true if we can insert NOP or prefixes automatically before the
422
392
// / the instruction to be emitted.
423
393
bool X86AsmBackend::canPadInst (const MCInst &Inst, MCObjectStreamer &OS) const {
@@ -441,9 +411,11 @@ bool X86AsmBackend::canPadInst(const MCInst &Inst, MCObjectStreamer &OS) const {
441
411
// semantic.
442
412
return false ;
443
413
444
- if (isRightAfterData (OS.getCurrentFragment (), PrevInstPosition))
445
- // If this instruction follows any data, there is no clear
446
- // instruction boundary, inserting a nop/prefix would change semantic.
414
+ // If this instruction follows any data, there is no clear instruction
415
+ // boundary, inserting a nop/prefix would change semantic.
416
+ auto Offset = OS.getCurFragSize ();
417
+ if (Offset && (OS.getCurrentFragment () != PrevInstPosition.first ||
418
+ Offset != PrevInstPosition.second ))
447
419
return false ;
448
420
449
421
return true ;
@@ -552,7 +524,7 @@ void X86AsmBackend::emitInstructionEnd(MCObjectStreamer &OS,
552
524
// Update PrevInstOpcode here, canPadInst() reads that.
553
525
MCFragment *CF = OS.getCurrentFragment ();
554
526
PrevInstOpcode = Inst.getOpcode ();
555
- PrevInstPosition = std::make_pair (CF, getSizeForInstFragment (CF ));
527
+ PrevInstPosition = std::make_pair (CF, OS. getCurFragSize ( ));
556
528
557
529
if (!canPadBranches (OS))
558
530
return ;
0 commit comments