@@ -404,131 +404,9 @@ class HexagonAsmBackend : public MCAsmBackend {
404
404
llvm_unreachable (errStr.str ().c_str ());
405
405
}
406
406
407
- // / ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
408
- // / data fragment, at the offset specified by the fixup and following the
409
- // / fixup kind as appropriate.
410
- void applyFixup (const MCFragment &, const MCFixup &Fixup,
411
- const MCValue &Target, MutableArrayRef<char > Data,
412
- uint64_t FixupValue, bool IsResolved) override {
413
-
414
- // When FixupValue is 0 the relocation is external and there
415
- // is nothing for us to do.
416
- if (!FixupValue) return ;
417
-
418
- MCFixupKind Kind = Fixup.getKind ();
419
- uint64_t Value;
420
- uint32_t InstMask;
421
- uint32_t Reloc;
422
-
423
- // LLVM gives us an encoded value, we have to convert it back
424
- // to a real offset before we can use it.
425
- uint32_t Offset = Fixup.getOffset ();
426
- unsigned NumBytes = getFixupKindNumBytes (Kind);
427
- assert (Offset + NumBytes <= Data.size () && " Invalid fixup offset!" );
428
- char *InstAddr = Data.data () + Offset;
429
-
430
- Value = adjustFixupValue (Kind, FixupValue);
431
- if (!Value)
432
- return ;
433
- int sValue = (int )Value;
434
-
435
- switch ((unsigned )Kind) {
436
- default :
437
- return ;
438
-
439
- case fixup_Hexagon_B7_PCREL:
440
- if (!(isIntN (7 , sValue )))
441
- HandleFixupError (7 , 2 , (int64_t )FixupValue, " B7_PCREL" );
442
- [[fallthrough]];
443
- case fixup_Hexagon_B7_PCREL_X:
444
- InstMask = 0x00001f18 ; // Word32_B7
445
- Reloc = (((Value >> 2 ) & 0x1f ) << 8 ) | // Value 6-2 = Target 12-8
446
- ((Value & 0x3 ) << 3 ); // Value 1-0 = Target 4-3
447
- break ;
448
-
449
- case fixup_Hexagon_B9_PCREL:
450
- if (!(isIntN (9 , sValue )))
451
- HandleFixupError (9 , 2 , (int64_t )FixupValue, " B9_PCREL" );
452
- [[fallthrough]];
453
- case fixup_Hexagon_B9_PCREL_X:
454
- InstMask = 0x003000fe ; // Word32_B9
455
- Reloc = (((Value >> 7 ) & 0x3 ) << 20 ) | // Value 8-7 = Target 21-20
456
- ((Value & 0x7f ) << 1 ); // Value 6-0 = Target 7-1
457
- break ;
458
-
459
- // Since the existing branches that use this relocation cannot be
460
- // extended, they should only be fixed up if the target is within range.
461
- case fixup_Hexagon_B13_PCREL:
462
- if (!(isIntN (13 , sValue )))
463
- HandleFixupError (13 , 2 , (int64_t )FixupValue, " B13_PCREL" );
464
- [[fallthrough]];
465
- case fixup_Hexagon_B13_PCREL_X:
466
- InstMask = 0x00202ffe ; // Word32_B13
467
- Reloc = (((Value >> 12 ) & 0x1 ) << 21 ) | // Value 12 = Target 21
468
- (((Value >> 11 ) & 0x1 ) << 13 ) | // Value 11 = Target 13
469
- ((Value & 0x7ff ) << 1 ); // Value 10-0 = Target 11-1
470
- break ;
471
-
472
- case fixup_Hexagon_B15_PCREL:
473
- if (!(isIntN (15 , sValue )))
474
- HandleFixupError (15 , 2 , (int64_t )FixupValue, " B15_PCREL" );
475
- [[fallthrough]];
476
- case fixup_Hexagon_B15_PCREL_X:
477
- InstMask = 0x00df20fe ; // Word32_B15
478
- Reloc = (((Value >> 13 ) & 0x3 ) << 22 ) | // Value 14-13 = Target 23-22
479
- (((Value >> 8 ) & 0x1f ) << 16 ) | // Value 12-8 = Target 20-16
480
- (((Value >> 7 ) & 0x1 ) << 13 ) | // Value 7 = Target 13
481
- ((Value & 0x7f ) << 1 ); // Value 6-0 = Target 7-1
482
- break ;
483
-
484
- case fixup_Hexagon_B22_PCREL:
485
- if (!(isIntN (22 , sValue )))
486
- HandleFixupError (22 , 2 , (int64_t )FixupValue, " B22_PCREL" );
487
- [[fallthrough]];
488
- case fixup_Hexagon_B22_PCREL_X:
489
- InstMask = 0x01ff3ffe ; // Word32_B22
490
- Reloc = (((Value >> 13 ) & 0x1ff ) << 16 ) | // Value 21-13 = Target 24-16
491
- ((Value & 0x1fff ) << 1 ); // Value 12-0 = Target 13-1
492
- break ;
493
-
494
- case fixup_Hexagon_B32_PCREL_X:
495
- InstMask = 0x0fff3fff ; // Word32_X26
496
- Reloc = (((Value >> 14 ) & 0xfff ) << 16 ) | // Value 25-14 = Target 27-16
497
- (Value & 0x3fff ); // Value 13-0 = Target 13-0
498
- break ;
499
-
500
- case FK_Data_1:
501
- case FK_Data_2:
502
- case FK_Data_4:
503
- case fixup_Hexagon_32:
504
- InstMask = 0xffffffff ; // Word32
505
- Reloc = Value;
506
- break ;
507
- }
508
-
509
- LLVM_DEBUG (dbgs () << " Name=" << getFixupKindInfo (Kind).Name << " ("
510
- << (unsigned )Kind << " )\n " );
511
- LLVM_DEBUG (
512
- uint32_t OldData = 0 ; for (unsigned i = 0 ; i < NumBytes; i++) OldData |=
513
- (InstAddr[i] << (i * 8 )) & (0xff << (i * 8 ));
514
- dbgs () << " \t BValue=0x" ; dbgs ().write_hex (Value) << " : AValue=0x" ;
515
- dbgs ().write_hex (FixupValue)
516
- << " : Offset=" << Offset << " : Size=" << Data.size () << " : OInst=0x" ;
517
- dbgs ().write_hex (OldData) << " : Reloc=0x" ; dbgs ().write_hex (Reloc););
518
-
519
- // For each byte of the fragment that the fixup touches, mask in the
520
- // bits from the fixup value. The Value has been "split up" into the
521
- // appropriate bitfields above.
522
- for (unsigned i = 0 ; i < NumBytes; i++){
523
- InstAddr[i] &= uint8_t (~InstMask >> (i * 8 )) & 0xff ; // Clear reloc bits
524
- InstAddr[i] |= uint8_t (Reloc >> (i * 8 )) & 0xff ; // Apply new reloc
525
- }
526
-
527
- LLVM_DEBUG (uint32_t NewData = 0 ;
528
- for (unsigned i = 0 ; i < NumBytes; i++) NewData |=
529
- (InstAddr[i] << (i * 8 )) & (0xff << (i * 8 ));
530
- dbgs () << " : NInst=0x" ; dbgs ().write_hex (NewData) << " \n " ;);
531
- }
407
+ void applyFixup (const MCFragment &, const MCFixup &, const MCValue &,
408
+ MutableArrayRef<char > Data, uint64_t FixupValue,
409
+ bool IsResolved) override ;
532
410
533
411
bool isInstRelaxable (MCInst const &HMI) const {
534
412
const MCInstrDesc &MCID = HexagonMCInstrInfo::getDesc (*MCII, HMI);
@@ -775,6 +653,130 @@ class HexagonAsmBackend : public MCAsmBackend {
775
653
776
654
} // namespace
777
655
656
+ void HexagonAsmBackend::applyFixup (const MCFragment &, const MCFixup &Fixup,
657
+ const MCValue &Target,
658
+ MutableArrayRef<char > Data,
659
+ uint64_t FixupValue, bool IsResolved) {
660
+ // When FixupValue is 0 the relocation is external and there
661
+ // is nothing for us to do.
662
+ if (!FixupValue)
663
+ return ;
664
+
665
+ MCFixupKind Kind = Fixup.getKind ();
666
+ uint64_t Value;
667
+ uint32_t InstMask;
668
+ uint32_t Reloc;
669
+
670
+ // LLVM gives us an encoded value, we have to convert it back
671
+ // to a real offset before we can use it.
672
+ uint32_t Offset = Fixup.getOffset ();
673
+ unsigned NumBytes = getFixupKindNumBytes (Kind);
674
+ assert (Offset + NumBytes <= Data.size () && " Invalid fixup offset!" );
675
+ char *InstAddr = Data.data () + Offset;
676
+
677
+ Value = adjustFixupValue (Kind, FixupValue);
678
+ if (!Value)
679
+ return ;
680
+ int sValue = (int )Value;
681
+
682
+ switch ((unsigned )Kind) {
683
+ default :
684
+ return ;
685
+
686
+ case fixup_Hexagon_B7_PCREL:
687
+ if (!(isIntN (7 , sValue )))
688
+ HandleFixupError (7 , 2 , (int64_t )FixupValue, " B7_PCREL" );
689
+ [[fallthrough]];
690
+ case fixup_Hexagon_B7_PCREL_X:
691
+ InstMask = 0x00001f18 ; // Word32_B7
692
+ Reloc = (((Value >> 2 ) & 0x1f ) << 8 ) | // Value 6-2 = Target 12-8
693
+ ((Value & 0x3 ) << 3 ); // Value 1-0 = Target 4-3
694
+ break ;
695
+
696
+ case fixup_Hexagon_B9_PCREL:
697
+ if (!(isIntN (9 , sValue )))
698
+ HandleFixupError (9 , 2 , (int64_t )FixupValue, " B9_PCREL" );
699
+ [[fallthrough]];
700
+ case fixup_Hexagon_B9_PCREL_X:
701
+ InstMask = 0x003000fe ; // Word32_B9
702
+ Reloc = (((Value >> 7 ) & 0x3 ) << 20 ) | // Value 8-7 = Target 21-20
703
+ ((Value & 0x7f ) << 1 ); // Value 6-0 = Target 7-1
704
+ break ;
705
+
706
+ // Since the existing branches that use this relocation cannot be
707
+ // extended, they should only be fixed up if the target is within range.
708
+ case fixup_Hexagon_B13_PCREL:
709
+ if (!(isIntN (13 , sValue )))
710
+ HandleFixupError (13 , 2 , (int64_t )FixupValue, " B13_PCREL" );
711
+ [[fallthrough]];
712
+ case fixup_Hexagon_B13_PCREL_X:
713
+ InstMask = 0x00202ffe ; // Word32_B13
714
+ Reloc = (((Value >> 12 ) & 0x1 ) << 21 ) | // Value 12 = Target 21
715
+ (((Value >> 11 ) & 0x1 ) << 13 ) | // Value 11 = Target 13
716
+ ((Value & 0x7ff ) << 1 ); // Value 10-0 = Target 11-1
717
+ break ;
718
+
719
+ case fixup_Hexagon_B15_PCREL:
720
+ if (!(isIntN (15 , sValue )))
721
+ HandleFixupError (15 , 2 , (int64_t )FixupValue, " B15_PCREL" );
722
+ [[fallthrough]];
723
+ case fixup_Hexagon_B15_PCREL_X:
724
+ InstMask = 0x00df20fe ; // Word32_B15
725
+ Reloc = (((Value >> 13 ) & 0x3 ) << 22 ) | // Value 14-13 = Target 23-22
726
+ (((Value >> 8 ) & 0x1f ) << 16 ) | // Value 12-8 = Target 20-16
727
+ (((Value >> 7 ) & 0x1 ) << 13 ) | // Value 7 = Target 13
728
+ ((Value & 0x7f ) << 1 ); // Value 6-0 = Target 7-1
729
+ break ;
730
+
731
+ case fixup_Hexagon_B22_PCREL:
732
+ if (!(isIntN (22 , sValue )))
733
+ HandleFixupError (22 , 2 , (int64_t )FixupValue, " B22_PCREL" );
734
+ [[fallthrough]];
735
+ case fixup_Hexagon_B22_PCREL_X:
736
+ InstMask = 0x01ff3ffe ; // Word32_B22
737
+ Reloc = (((Value >> 13 ) & 0x1ff ) << 16 ) | // Value 21-13 = Target 24-16
738
+ ((Value & 0x1fff ) << 1 ); // Value 12-0 = Target 13-1
739
+ break ;
740
+
741
+ case fixup_Hexagon_B32_PCREL_X:
742
+ InstMask = 0x0fff3fff ; // Word32_X26
743
+ Reloc = (((Value >> 14 ) & 0xfff ) << 16 ) | // Value 25-14 = Target 27-16
744
+ (Value & 0x3fff ); // Value 13-0 = Target 13-0
745
+ break ;
746
+
747
+ case FK_Data_1:
748
+ case FK_Data_2:
749
+ case FK_Data_4:
750
+ case fixup_Hexagon_32:
751
+ InstMask = 0xffffffff ; // Word32
752
+ Reloc = Value;
753
+ break ;
754
+ }
755
+
756
+ LLVM_DEBUG (dbgs () << " Name=" << getFixupKindInfo (Kind).Name << " ("
757
+ << (unsigned )Kind << " )\n " );
758
+ LLVM_DEBUG (
759
+ uint32_t OldData = 0 ; for (unsigned i = 0 ; i < NumBytes; i++) OldData |=
760
+ (InstAddr[i] << (i * 8 )) & (0xff << (i * 8 ));
761
+ dbgs () << " \t BValue=0x" ; dbgs ().write_hex (Value) << " : AValue=0x" ;
762
+ dbgs ().write_hex (FixupValue)
763
+ << " : Offset=" << Offset << " : Size=" << Data.size () << " : OInst=0x" ;
764
+ dbgs ().write_hex (OldData) << " : Reloc=0x" ; dbgs ().write_hex (Reloc););
765
+
766
+ // For each byte of the fragment that the fixup touches, mask in the
767
+ // bits from the fixup value. The Value has been "split up" into the
768
+ // appropriate bitfields above.
769
+ for (unsigned i = 0 ; i < NumBytes; i++) {
770
+ InstAddr[i] &= uint8_t (~InstMask >> (i * 8 )) & 0xff ; // Clear reloc bits
771
+ InstAddr[i] |= uint8_t (Reloc >> (i * 8 )) & 0xff ; // Apply new reloc
772
+ }
773
+
774
+ LLVM_DEBUG (uint32_t NewData = 0 ;
775
+ for (unsigned i = 0 ; i < NumBytes; i++) NewData |=
776
+ (InstAddr[i] << (i * 8 )) & (0xff << (i * 8 ));
777
+ dbgs () << " : NInst=0x" ; dbgs ().write_hex (NewData) << " \n " ;);
778
+ }
779
+
778
780
// MCAsmBackend
779
781
MCAsmBackend *llvm::createHexagonAsmBackend (Target const &T,
780
782
const MCSubtargetInfo &STI,
0 commit comments